-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
119 lines (95 loc) · 3.58 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"github.com/EliCDavis/vector"
)
// var resRetained, resClipped mesh.Model
func BenchmarkSplitByPlane(b *testing.B) {
// fbx := loadModel("dragon_vrip.fbx")
// plane := NewPlane(vector.Vector3Zero(), vector.Vector3Forward())
// fbx := loadModel("HIB-model.fbx")
// plane := NewPlane(vector.NewVector3(105.4350, 119.4877, 77.9060), vector.Vector3Up())
// b.ResetTimer()
for n := 0; n < b.N; n++ {
// always record the result of func to prevent
// the compiler eliminating the function call.
SplitByPlaneProgram("dragon_vrip.fbx", NewPlane(vector.Vector3Zero(), vector.Vector3Forward()), 3, ioutil.Discard, ioutil.Discard)
}
}
func TestInsertionSort(t *testing.T) {
// ****************************** ARRANGE *********************************
diffs := []Diff{
NewArrayPropertyDiff(1, nil),
NewArrayPropertyDiff(2, nil),
NewArrayPropertyDiff(4, nil),
NewArrayPropertyDiff(5, nil),
}
newDif := NewArrayPropertyDiff(3, nil)
// ******************************** ACT ***********************************
results := insertNewDiff(diffs, newDif)
// ******************************* ASSERT *********************************
// Nothings changed
assert.Len(t, diffs, 4)
assert.Equal(t, uint64(1), diffs[0].NodeID())
assert.Equal(t, uint64(2), diffs[1].NodeID())
assert.Equal(t, uint64(4), diffs[2].NodeID())
assert.Equal(t, uint64(5), diffs[3].NodeID())
// Results
assert.Len(t, results, 5)
assert.Equal(t, uint64(1), results[0].NodeID())
assert.Equal(t, uint64(2), results[1].NodeID())
assert.Equal(t, uint64(3), results[2].NodeID())
assert.Equal(t, uint64(4), results[3].NodeID())
assert.Equal(t, uint64(5), results[4].NodeID())
}
func TestInsertionSortOnEmptyArray(t *testing.T) {
// ****************************** ARRANGE *********************************
var diffs []Diff
newDif := NewArrayPropertyDiff(3, nil)
// ******************************** ACT ***********************************
results := insertNewDiff(diffs, newDif)
// ******************************* ASSERT *********************************
assert.Len(t, results, 1)
assert.Equal(t, uint64(3), results[0].NodeID())
}
func TestCombiningSortedArrays(t *testing.T) {
// ****************************** ARRANGE *********************************
diffs1 := []Diff{
NewArrayPropertyDiff(1, nil),
NewArrayPropertyDiff(2, nil),
NewArrayPropertyDiff(4, nil),
NewArrayPropertyDiff(5, nil),
}
diffs2 := []Diff{
NewArrayPropertyDiff(0, nil),
NewArrayPropertyDiff(2, nil),
NewArrayPropertyDiff(6, nil),
NewArrayPropertyDiff(7, nil),
}
var diffs3 []Diff
diffs4 := []Diff{
NewArrayPropertyDiff(1, nil),
NewArrayPropertyDiff(7, nil),
NewArrayPropertyDiff(8, nil),
NewArrayPropertyDiff(9, nil),
}
// ******************************** ACT ***********************************
results := combineSorted(diffs1, diffs2, diffs3, diffs4)
// ******************************* ASSERT *********************************
if assert.Len(t, results, 12) {
assert.Equal(t, uint64(0), results[0].NodeID())
assert.Equal(t, uint64(1), results[1].NodeID())
assert.Equal(t, uint64(1), results[2].NodeID())
assert.Equal(t, uint64(2), results[3].NodeID())
assert.Equal(t, uint64(2), results[4].NodeID())
assert.Equal(t, uint64(4), results[5].NodeID())
assert.Equal(t, uint64(5), results[6].NodeID())
assert.Equal(t, uint64(6), results[7].NodeID())
assert.Equal(t, uint64(7), results[8].NodeID())
assert.Equal(t, uint64(7), results[9].NodeID())
assert.Equal(t, uint64(8), results[10].NodeID())
assert.Equal(t, uint64(9), results[11].NodeID())
}
}