-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject_test.go
More file actions
97 lines (93 loc) · 2.21 KB
/
object_test.go
File metadata and controls
97 lines (93 loc) · 2.21 KB
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
package space
import (
"testing"
)
func TestNewObject(t *testing.T) {
cases := []struct {
Location Cartesian
Orientation Spherical
Rotation Spherical
Expected Object
}{
{
Location: Origin.Cartesian,
Orientation: AxisX.Spherical,
Rotation: AxisY.Spherical,
Expected: Object{
location: Origin.Cartesian,
orientation: AxisX.Spherical,
rotation: AxisY.Spherical,
},
},
{
Location: Origin.Cartesian,
Orientation: AxisX.Spherical,
Rotation: AxisZ.Spherical,
Expected: Object{
location: Origin.Cartesian,
orientation: AxisX.Spherical,
rotation: AxisZ.Spherical,
},
},
}
for i, c := range cases {
actual := NewObject(c.Location, c.Orientation, c.Rotation)
if !ObjectsEqual(&c.Expected, actual) {
t.Fatalf("NewObject %v failed. Objects were not equal:\n\tExpected: %v,\n\tActual: %v", i, &c.Expected, actual)
}
}
}
func TestObjectMove(t *testing.T) {
initial := Object{
location: Origin.Cartesian,
orientation: AxisX.Spherical,
rotation: AxisZ.Spherical,
}
cases := []struct {
Location Cartesian
Orientation Spherical
Rotation Spherical
Expected Object
}{
{
Location: AxisZN.Cartesian,
Orientation: AxisX.Spherical,
Rotation: AxisY.Spherical,
Expected: Object{
location: AxisZN.Cartesian,
orientation: AxisX.Spherical,
rotation: AxisY.Spherical,
},
},
{
Location: AxisYN.Cartesian,
Orientation: AxisX.Spherical,
Rotation: AxisZ.Spherical,
Expected: Object{
location: AxisYN.Cartesian,
orientation: AxisX.Spherical,
rotation: AxisZ.Spherical,
},
},
}
for i, c := range cases {
actual := initial
actual.Move(c.Location, c.Orientation, c.Rotation)
if !ObjectsEqual(&c.Expected, &actual) {
t.Fatalf("NewObject %v failed. Objects were not equal:\n\tExpected: %v,\n\tActual: %v", i, &c.Expected, actual)
}
}
}
// ObjectsEqual compares objects
func ObjectsEqual(a, b *Object) bool {
if !CartesiansEqual(a.GetLocation(), b.GetLocation()) {
return false
}
if !SphericalsEqual(a.GetOrientation(), b.GetOrientation()) {
return false
}
if !SphericalsEqual(a.GetRotation(), b.GetRotation()) {
return false
}
return true
}