Esempio n. 1
0
func TestTINExpandCollapseOne(t *testing.T) {
	N := createTestTreeNode
	root := CreateTreeInternalRoot(N(0,
		N(10,
			N(11), N(12), N(13), N(14)),
		N(20,
			N(21), N(22), N(23), N(24)),
		N(30,
			N(31), N(32), N(33), N(34)),
	))

	root.Child(1).Expand()
	test.AssertEquals(t, root.descendants, 7)
	test.AssertEquals(t, gxui.AdapterItem(10), root.ItemAt(0))
	test.AssertEquals(t, gxui.AdapterItem(20), root.ItemAt(1))
	test.AssertEquals(t, gxui.AdapterItem(21), root.ItemAt(2))
	test.AssertEquals(t, gxui.AdapterItem(24), root.ItemAt(5))
	test.AssertEquals(t, gxui.AdapterItem(30), root.ItemAt(6))

	root.Child(1).Collapse()
	test.AssertEquals(t, root.descendants, 3)
	test.AssertEquals(t, gxui.AdapterItem(10), root.ItemAt(0))
	test.AssertEquals(t, gxui.AdapterItem(20), root.ItemAt(1))
	test.AssertEquals(t, gxui.AdapterItem(30), root.ItemAt(2))
}
Esempio n. 2
0
func TestTINFindByIndex(t *testing.T) {
	N := createTestTreeNode
	root := CreateTreeInternalRoot(N(0,
		/*0*/ N(100,
			/*1*/ N(110),
			/*2*/ N(120,
				/*3*/ N(121),
				/*4*/ N(122),
				/*5*/ N(123)),
			/*6*/ N(130),
			/*7*/ N(140,
				/*8*/ N(141),
				/*9*/ N(141)))))

	root.ExpandAll()
	test.AssertEquals(t, 10, root.descendants)

	n, i, d := root.FindByIndex(0)
	test.AssertEquals(t, root, n)
	test.AssertEquals(t, 0, i)
	test.AssertEquals(t, 0, d)

	n, i, d = root.FindByIndex(4)
	test.AssertEquals(t, root.Child(0).Child(1), n)
	test.AssertEquals(t, 1, i)
	test.AssertEquals(t, 2, d)

	n, i, d = root.FindByIndex(9)
	test.AssertEquals(t, root.Child(0).Child(3), n)
	test.AssertEquals(t, 1, i)
	test.AssertEquals(t, 2, d)
}
Esempio n. 3
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))
}
Esempio n. 4
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)
}
Esempio n. 5
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))
}
Esempio n. 6
0
func TestTINFlatSimple(t *testing.T) {
	N := createTestTreeNode
	root := CreateTreeInternalRoot(N(0, N(10), N(20), N(30)))

	test.AssertEquals(t, 3, root.descendants)
	test.AssertEquals(t, gxui.AdapterItem(10), root.ItemAt(0))
	test.AssertEquals(t, gxui.AdapterItem(20), root.ItemAt(1))
	test.AssertEquals(t, gxui.AdapterItem(30), root.ItemAt(2))
}
Esempio n. 7
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)
}
Esempio n. 8
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)
}
Esempio n. 9
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)
}
Esempio n. 10
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)
}
Esempio n. 11
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)
}
Esempio n. 12
0
func TestU64ListReplaceFromEmpty(t *testing.T) {
	l := &U64List{}
	Replace(l, CreateU64Inc(0, 10))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(0, 10),
	}, l)
}
Esempio n. 13
0
func TestU64ListRemoveTrimFront(t *testing.T) {
	l := &U64List{CreateU64Inc(10, 20)}
	Remove(l, CreateU64Inc(5, 14))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(15, 20),
	}, l)
}
Esempio n. 14
0
func TestU64ListMergeExtendSingleBack(t *testing.T) {
	l := &U64List{CreateU64Inc(3, 5)}
	Merge(l, CreateU64Inc(5, 7))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(3, 7),
	}, l)
}
Esempio n. 15
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)
}
Esempio n. 16
0
func TestU64ListRemoveAfterSingle(t *testing.T) {
	l := &U64List{CreateU64Inc(3, 5)}
	Remove(l, CreateU64Inc(6, 7))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(3, 5),
	}, l)
}
Esempio n. 17
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))
}
Esempio n. 18
0
func TestU64ListMergeFromEmpty(t *testing.T) {
	l := &U64List{}
	Merge(l, CreateU64Inc(0, 0))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(0, 0),
	}, l)
}
Esempio n. 19
0
func TestU64ListDuplicate0Len(t *testing.T) {
	l := &U64List{
		U64{10, 0},
	}
	Merge(l, U64{10, 0})
	test.AssertEquals(t, &U64List{U64{10, 0}}, l)
}
Esempio n. 20
0
func TestU64ListReplaceSingleWhole(t *testing.T) {
	l := &U64List{CreateU64Inc(5, 10)}
	Replace(l, CreateU64Inc(5, 10))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(5, 10),
	}, l)
}
Esempio n. 21
0
func TestTINDeepNoExpand(t *testing.T) {
	N := createTestTreeNode
	root := CreateTreeInternalRoot(N(0,
		N(10,
			N(11), N(12), N(13), N(14)),
		N(20,
			N(21), N(22), N(23), N(24)),
		N(30,
			N(31), N(32), N(33), N(34)),
	))

	test.AssertEquals(t, 3, root.descendants)
	test.AssertEquals(t, gxui.AdapterItem(10), root.ItemAt(0))
	test.AssertEquals(t, gxui.AdapterItem(20), root.ItemAt(1))
	test.AssertEquals(t, gxui.AdapterItem(30), root.ItemAt(2))
}
Esempio n. 22
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))
}
Esempio n. 23
0
func TestU64ListRemoveBeforeSingle(t *testing.T) {
	l := &U64List{CreateU64Inc(3, 5)}
	Remove(l, CreateU64Inc(0, 2))
	test.AssertEquals(t, &U64List{
		CreateU64Inc(3, 5),
	}, l)
}
Esempio n. 24
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))
}
Esempio n. 25
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))
}
Esempio n. 26
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))
}
Esempio n. 27
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)
}
Esempio n. 28
0
func TestTextSelectionMergeExtendEnd(t *testing.T) {
	s1 := TextSelection{6, 9, true}
	s2 := TextSelection{8, 15, false}
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		TextSelection{6, 15, false},
	}, l)
}
Esempio n. 29
0
func TestTextSelectionMergeDuplicate0Len(t *testing.T) {
	s1 := TextSelection{2, 2, false}
	s2 := TextSelection{2, 2, true}
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		TextSelection{2, 2, true},
	}, l)
}
Esempio n. 30
0
func TestTextSelectionMergeEncompass(t *testing.T) {
	s1 := TextSelection{6, 9, false}
	s2 := TextSelection{5, 10, true}
	l := TextSelectionList{s1}
	interval.Merge(&l, s2)
	test.AssertEquals(t, TextSelectionList{
		TextSelection{5, 10, true},
	}, l)
}