-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec4_test.go
186 lines (146 loc) · 4.57 KB
/
vec4_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package gogm
import (
"testing"
"github.com/smyrman/subx"
)
func TestVec4CopyVec4(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[uint]{1, 2, 3, 4}
expected := Vec4[int]{1, 2, 3, 4}
Vec4CopyVec4(&v1, &v2)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4CopyVec2(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec2[uint]{1, 2}
expected := Vec4[int]{1, 2, 0, 0}
Vec4CopyVec2(&v1, &v2)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4CopyVec3(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec3[uint]{1, 2, 3}
expected := Vec4[int]{1, 2, 3, 0}
Vec4CopyVec3(&v1, &v2)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4String(t *testing.T) {
v1 := Vec4[int]{1, 2, 3, 4}
expected := "{1, 2, 3, 4}"
result := v1.String()
t.Run("Expect correct result", subx.Test(subx.Value(result), subx.CompareEqual(expected)))
}
func TestVec4Len(t *testing.T) {
v1 := Vec4[int]{1, 1, 1, 1}
expected := float64(2)
result := v1.Len()
t.Run("Expect correct result", subx.Test(subx.Value(result), subx.CompareEqual(expected)))
}
func TestVec4Normalize(t *testing.T) {
v1 := Vec4[float64]{}
v2 := Vec4[float64]{0, 3, 0, 0}
expected := Vec4[float64]{0, 1, 0, 0}
v1.Normalize(&v2)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4Inverse(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{1, 2, 3, 4}
expected := Vec4[int]{-1, -2, -3, -4}
v1.Inverse(&v2)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4Add(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{1, 2, 3, 4}
v3 := Vec4[int]{5, 6, 7, 8}
expected := Vec4[int]{6, 8, 10, 12}
v1.Add(&v2, &v3)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4Sub(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{1, 2, 3, 4}
v3 := Vec4[int]{5, 6, 7, 8}
expected := Vec4[int]{-4, -4, -4, -4}
v1.Sub(&v2, &v3)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4Mul(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{1, 2, 3, 4}
v3 := Vec4[int]{5, 6, 7, 8}
expected := Vec4[int]{5, 12, 21, 32}
v1.Mul(&v2, &v3)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4Div(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{4, 5, 6, 12}
v3 := Vec4[int]{2, 1, 3, 4}
expected := Vec4[int]{2, 5, 2, 3}
v1.Div(&v2, &v3)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4AddS(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{1, 2, 3, 4}
s := int(5)
expected := Vec4[int]{6, 7, 8, 9}
v1.AddS(&v2, s)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4SubS(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{1, 2, 3, 4}
s := int(5)
expected := Vec4[int]{-4, -3, -2, -1}
v1.SubS(&v2, s)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4MulS(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{1, 2, 3, 4}
s := int(5)
expected := Vec4[int]{5, 10, 15, 20}
v1.MulS(&v2, s)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4DivS(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{2, 4, 8, 18}
s := int(2)
expected := Vec4[int]{1, 2, 4, 9}
v1.DivS(&v2, s)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4CrossHomog(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{2, 1, -1, 0}
v3 := Vec4[int]{-3, 4, 1, 0}
expected := Vec4[int]{5, 1, 11, 0}
v1.CrossHomog(&v2, &v3)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4CrossHomogFast(t *testing.T) {
v1 := Vec4[int]{}
v2 := Vec4[int]{2, 1, -1, 0}
v3 := Vec4[int]{-3, 4, 1, 0}
expected := Vec4[int]{5, 1, 11, 0}
v1.CrossHomogFast(&v2, &v3)
t.Run("Expect correct result", subx.Test(subx.Value(v1), subx.CompareEqual(expected)))
}
func TestVec4Dot(t *testing.T) {
v1 := Vec4[int]{1, 2, 3, 4}
v2 := Vec4[int]{5, 6, 7, 8}
expected := int(70)
result := v1.Dot(&v2)
t.Run("Expect correct result", subx.Test(subx.Value(result), subx.CompareEqual(expected)))
}
func TestVec4DotHomog(t *testing.T) {
v1 := Vec4[int]{1, 2, 3, 1}
v2 := Vec4[int]{4, 5, 6, 1}
expected := int(32)
result := v1.DotHomog(&v2)
t.Run("Expect correct result", subx.Test(subx.Value(result), subx.CompareEqual(expected)))
}