-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathabs_test.go
95 lines (90 loc) · 2.42 KB
/
abs_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
package govec
import "testing"
func TestV2F_Abs(t *testing.T) {
vectors := []V2F[float64]{
{X: 0.0, Y: 0.0},
{X: -1.0, Y: 0.0},
{X: 0.0, Y: -1.0},
{X: 1, Y: 1},
}
expectedAbsResult := []V2F[float64]{
{X: 0.0, Y: 0.0},
{X: 1.0, Y: 0.0},
{X: 0.0, Y: 1.0},
{X: 1.0, Y: 1.0},
}
for idx, vector := range vectors {
absV := vector.Abs()
expectedAbsV := expectedAbsResult[idx]
if absV.X != expectedAbsV.X || absV.Y != expectedAbsV.Y {
t.Errorf("%#v.Abs() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, absV)
}
}
}
func TestV2F_AbsInPlace(t *testing.T) {
vectors := []V2F[float64]{
{X: 0.0, Y: 0.0},
{X: -1.0, Y: 0.0},
{X: 0.0, Y: -1.0},
{X: 1, Y: 1},
}
expectedAbsInPlaceResult := []V2F[float64]{
{X: 0.0, Y: 0.0},
{X: 1.0, Y: 0.0},
{X: 0.0, Y: 1.0},
{X: 1.0, Y: 1.0},
}
for idx, vector := range vectors {
vector.AbsInPlace()
expectedAbsV := expectedAbsInPlaceResult[idx]
if vector.X != expectedAbsV.X || vector.Y != expectedAbsV.Y {
t.Errorf("%#v.AbsInPlace() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, vector)
}
}
}
func TestV3F_Abs(t *testing.T) {
vectors := []V3F[float64]{
{X: 0.0, Y: 0.0, Z: 0.0},
{X: -1.0, Y: 0.0, Z: 0.0},
{X: 0.0, Y: -1.0, Z: 0.0},
{X: 0.0, Y: 1.0, Z: -1.0},
{X: 1, Y: 1, Z: 0},
}
expectedAbsResult := []V3F[float64]{
{X: 0.0, Y: 0.0, Z: 0.0},
{X: 1.0, Y: 0.0, Z: 0.0},
{X: 0.0, Y: 1.0, Z: 0.0},
{X: 0.0, Y: 1.0, Z: 1.0},
{X: 1.0, Y: 1.0, Z: 0.0},
}
for idx, vector := range vectors {
absV := vector.Abs()
expectedAbsV := expectedAbsResult[idx]
if absV.X != expectedAbsV.X || absV.Y != expectedAbsV.Y || absV.Z != expectedAbsV.Z {
t.Errorf("%#v.Abs() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, absV)
}
}
}
func TestV3F_AbsInPlace(t *testing.T) {
vectors := []V3F[float64]{
{X: 0.0, Y: 0.0, Z: 0.0},
{X: -1.0, Y: 0.0, Z: 0.0},
{X: 0.0, Y: -1.0, Z: 0.0},
{X: 0.0, Y: 1.0, Z: -1.0},
{X: 1, Y: 1, Z: 0},
}
expectedAbsInPlaceResult := []V3F[float64]{
{X: 0.0, Y: 0.0, Z: 0.0},
{X: 1.0, Y: 0.0, Z: 0.0},
{X: 0.0, Y: 1.0, Z: 0.0},
{X: 0.0, Y: 1.0, Z: 1.0},
{X: 1.0, Y: 1.0, Z: 0.0},
}
for idx, vector := range vectors {
vector.AbsInPlace()
expectedAbsV := expectedAbsInPlaceResult[idx]
if vector.X != expectedAbsV.X || vector.Y != expectedAbsV.Y || vector.Z != expectedAbsV.Z {
t.Errorf("%#v.AbsInPlace() incorrect. expected: %#v, got: %#v", vector, expectedAbsV, vector)
}
}
}