Ejemplo n.º 1
0
func TestTBCLineIndent(t *testing.T) {
	c := parseTBC("  ÀÁ\n    BB\nĆ\n      D\n   EE")
	test.AssertEquals(t, 2, c.LineIndent(0))
	test.AssertEquals(t, 4, c.LineIndent(1))
	test.AssertEquals(t, 0, c.LineIndent(2))
	test.AssertEquals(t, 6, c.LineIndent(3))
	test.AssertEquals(t, 3, c.LineIndent(4))
}
Ejemplo n.º 2
0
func TestU64ListIntersectSingleMiddle(t *testing.T) {
	l := U64List{
		CreateU64Inc(10, 20),
	}
	first, count := Intersect(&l, CreateU64Inc(12, 18))
	test.AssertEquals(t, 0, first)
	test.AssertEquals(t, 1, count)
}
Ejemplo n.º 3
0
func TestCreateMat3PositionToBarycentric(t *testing.T) {
	a := Vec2{+0.0, -1.0}
	b := Vec2{-1.0, 1.0}
	c := Vec2{+1.0, 1.0}
	m := CreateMat3PositionToBarycentric(a, b, c)
	test.AssertEquals(t, Vec3{1.0, 0.0, 1.0}, a.Vec3(1).MulM(m))
	test.AssertEquals(t, Vec3{0.0, 1.0, 1.0}, b.Vec3(1).MulM(m))
	test.AssertEquals(t, Vec3{0.0, 0.0, 1.0}, c.Vec3(1).MulM(m))
}
Ejemplo n.º 4
0
func TestU64ListIntersectOverlapLastTwo(t *testing.T) {
	l := U64List{
		CreateU64Inc(10, 20),
		CreateU64Inc(30, 40),
		CreateU64Inc(50, 60),
	}
	first, count := Intersect(&l, CreateU64Inc(35, 60))
	test.AssertEquals(t, 1, first)
	test.AssertEquals(t, 2, count)
}
Ejemplo n.º 5
0
func TestU64ListIntersectOverlapThree(t *testing.T) {
	l := U64List{
		CreateU64Inc(10, 20),
		CreateU64Inc(30, 40),
		CreateU64Inc(50, 60),
	}
	first, count := Intersect(&l, CreateU64Inc(15, 55))
	test.AssertEquals(t, 0, first)
	test.AssertEquals(t, 3, count)
}
Ejemplo n.º 6
0
func TestEventNoArgs(t *testing.T) {
	e := CreateEvent(func() {})

	fired := false
	e.Listen(func() { fired = true })
	test.AssertEquals(t, false, fired)

	e.Fire()
	test.AssertEquals(t, true, fired)
}
Ejemplo n.º 7
0
func TestEventEmptyVariadic(t *testing.T) {
	e := CreateEvent(func(...int) {})

	fired := false
	e.Listen(func(va ...int) {
		test.AssertEquals(t, 0, len(va))
		fired = true
	})
	e.Fire()
	test.AssertEquals(t, true, fired)
}
Ejemplo n.º 8
0
func TestEventSingleVariadic(t *testing.T) {
	e := CreateEvent(func(...int) {})

	fired := false
	e.Listen(func(va ...int) {
		test.AssertEquals(t, 3, len(va))

		test.AssertEquals(t, 2, va[0])
		test.AssertEquals(t, 3, va[1])
		test.AssertEquals(t, 4, va[2])
		fired = true
	})
	e.Fire(2, 3, 4)
	test.AssertEquals(t, true, fired)
}
Ejemplo n.º 9
0
func TestU64ListDuplicate0Len(t *testing.T) {
	l := &U64List{
		U64{10, 0},
	}
	Merge(l, U64{10, 0})
	test.AssertEquals(t, &U64List{U64{10, 0}}, l)
}
Ejemplo n.º 10
0
func TestU64ListRemoveTrimFront(t *testing.T) {
	l := &U64List{CreateU64Inc(10, 20)}
	Remove(l, CreateU64Inc(5, 14))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(15, 20),
	}, l)
}
Ejemplo n.º 11
0
func TestU64ListRemoveAfterSingle(t *testing.T) {
	l := &U64List{CreateU64Inc(3, 5)}
	Remove(l, CreateU64Inc(6, 7))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(3, 5),
	}, l)
}
Ejemplo n.º 12
0
func TestU64ListRemoveBeforeSingle(t *testing.T) {
	l := &U64List{CreateU64Inc(3, 5)}
	Remove(l, CreateU64Inc(0, 2))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(3, 5),
	}, l)
}
Ejemplo n.º 13
0
func TestU64ListReplaceSingleWhole(t *testing.T) {
	l := &U64List{CreateU64Inc(5, 10)}
	Replace(l, CreateU64Inc(5, 10))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(5, 10),
	}, l)
}
Ejemplo n.º 14
0
func TestU64ListReplaceFromEmpty(t *testing.T) {
	l := &U64List{}
	Replace(l, CreateU64Inc(0, 10))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(0, 10),
	}, l)
}
Ejemplo n.º 15
0
func TestU64ListMergeExtendSingleBack(t *testing.T) {
	l := &U64List{CreateU64Inc(3, 5)}
	Merge(l, CreateU64Inc(5, 7))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(3, 7),
	}, l)
}
Ejemplo n.º 16
0
// Extending tests
func TestU64ListMergeExtendSingleFront(t *testing.T) {
	l := &U64List{CreateU64Inc(3, 5)}
	Merge(l, CreateU64Inc(0, 3))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(0, 5),
	}, l)
}
Ejemplo n.º 17
0
func TestTriangluateConcave(t *testing.T) {
	/*
	         A
	     H       B

	   G           C

	     F       D
	         E
	*/
	A := v(0, -3)
	B := v(4, -2)
	C := v(6, -0)
	D := v(4, 2)
	E := v(0, 3)
	F := v(-4, 2)
	G := v(-6, -0)
	H := v(-4, -2)
	edges := []math.Vec2{A, B, C, D, E, F, G, H}
	tris := []math.Vec2{
		A, B, C,
		A, C, D,
		A, D, E,
		A, E, F,
		A, F, G,
		A, G, H,
	}
	test.AssertEquals(t, tris, triangulate(edges))
}
Ejemplo n.º 18
0
func TestTriangluateConvex4(t *testing.T) {
	/*
	    J---------------A
	   I                 B
	   |            D    |
	   |           E  \  |
	   H             \   C
	    G--------------F
	*/

	A := v(404, 120)
	B := v(412.4853, 123.51472)
	C := v(416, 177.90715)
	D := v(280.82632, 146.21126)
	E := v(271.39908, 151.5048)
	F := v(384.94205, 208)
	G := v(20, 208)
	H := v(11.514719, 204.48528)
	I := v(8.000002, 132)
	J := v(11.514719, 123.51472)

	edges := []math.Vec2{A, B, C, C, D, E, F, G, H, I, J}
	tris := []math.Vec2{
		A, B, C,
		A, C, D,
		E, F, G,
		E, G, H,
		E, H, I,
		E, I, J,
		J, A, D,
		J, D, E,
	}
	test.AssertEquals(t, tris, triangulate(edges))
}
Ejemplo n.º 19
0
func TestU64ListMergeFromEmpty(t *testing.T) {
	l := &U64List{}
	Merge(l, CreateU64Inc(0, 0))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(0, 0),
	}, l)
}
Ejemplo n.º 20
0
func TestTriangluateConvex2(t *testing.T) {
	/*
	   A-----------------B
	   |                 |
	   |                 |
	   F-------------E   C
	                  \ /
	                   D
	*/

	A := v(462, 531)
	B := v(576, 531)
	C := v(576, 557)
	D := v(573, 572)
	E := v(566, 557)
	F := v(462, 557)

	edges := []math.Vec2{A, B, C, C, D, E, F}
	tris := []math.Vec2{
		A, B, C,
		C, D, E,
		E, F, A,
		E, A, C,
	}
	test.AssertEquals(t, tris, triangulate(edges))
}
Ejemplo n.º 21
0
func TestTriangluateConvex3(t *testing.T) {
	/*
	    B---------------C
	   A                 D
	   |            F    |
	   |           G  \  |
	   J             \   E
	    I--------------H
	*/

	A := v(8.000002, 132)
	B := v(11.514719, 123.514)
	C := v(404, 120)
	D := v(412.4853, 123.51472)
	E := v(416, 176.98395)
	F := v(300.47543, 139.39261)
	G := v(290.65604, 143.82726)
	H := v(392.73557, 208)
	I := v(20, 208)
	J := v(11.514719, 204.48528)

	edges := []math.Vec2{A, B, C, C, D, E, F, G, H, I, J}
	tris := []math.Vec2{
		A, B, C,
		A, C, D,
		D, E, F,
		G, H, I,
		G, I, J,
		G, J, A,
		A, D, F,
		A, F, G,
	}
	test.AssertEquals(t, tris, triangulate(edges))
}
Ejemplo n.º 22
0
func TestTriangluateConvex(t *testing.T) {
	/*
	       D-------E
	       |       |
	   B---C   G   |
	   |       | \ |
	   A-------H   F
	*/
	A := v(0, 2)
	B := v(0, 1)
	C := v(1, 1)
	D := v(1, 0)
	E := v(3, 0)
	F := v(3, 2)
	G := v(2, 1)
	H := v(2, 2)

	edges := []math.Vec2{A, B, C, D, E, F, G, H}
	tris := []math.Vec2{
		A, B, C,
		C, D, E,
		E, F, G,
		G, H, A,
		G, A, C,
		G, C, E,
	}
	test.AssertEquals(t, tris, triangulate(edges))
}
Ejemplo n.º 23
0
func TestU64ListMergeSingleAfter(t *testing.T) {
	l := &U64List{CreateU64Inc(0, 5)}
	Merge(l, CreateU64Inc(10, 20))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(0, 5),
		CreateU64Inc(10, 20),
	}, l)
}
Ejemplo n.º 24
0
func TestU64ListDuplicate1Len(t *testing.T) {
	l := &U64List{
		CreateU64Inc(10, 10),
	}
	Merge(l, CreateU64Inc(10, 10))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(10, 10),
	}, l)
}
Ejemplo n.º 25
0
func TestTextSelectionMergeExtendEnd(t *testing.T) {
	s1 := CreateTextSelection(6, 9, true)
	s2 := CreateTextSelection(8, 15, false)
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		CreateTextSelection(6, 15, false),
	}, l)
}
Ejemplo n.º 26
0
func TestTextSelectionMergeDuplicate0Len(t *testing.T) {
	s1 := CreateTextSelection(2, 2, false)
	s2 := CreateTextSelection(2, 2, true)
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		CreateTextSelection(2, 2, true),
	}, l)
}
Ejemplo n.º 27
0
func TestTextSelectionMergeEncompass(t *testing.T) {
	s1 := CreateTextSelection(6, 9, false)
	s2 := CreateTextSelection(5, 10, true)
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		CreateTextSelection(5, 10, true),
	}, l)
}
Ejemplo n.º 28
0
func TestU64ListReplaceSingleInner(t *testing.T) {
	l := &U64List{CreateU64Inc(5, 25)}
	Replace(l, CreateU64Inc(15, 20))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(5, 14),
		CreateU64Inc(15, 20),
		CreateU64Inc(21, 25),
	}, l)
}
Ejemplo n.º 29
0
func TestU64ListRemoveAll1(t *testing.T) {
	l := &U64List{
		CreateU64Inc(10, 20),
		CreateU64Inc(30, 40),
		CreateU64Inc(50, 60),
	}
	Remove(l, CreateU64Inc(0, 100))
	test.AssertEquals(t, &U64List{}, l)
}
Ejemplo n.º 30
0
func TestU64ListMergeEdgeBack(t *testing.T) {
	l := &U64List{
		CreateU64Inc(10, 20),
	}
	Merge(l, CreateU64Inc(19, 20))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(10, 20),
	}, l)
}