-
Notifications
You must be signed in to change notification settings - Fork 7
/
rand_test.go
62 lines (49 loc) · 2.07 KB
/
rand_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
package govec
import (
"math"
"testing"
)
func Test_RandV2F(t *testing.T) {
t.Run("generate 2 different random f32 vectors, shouldn't be equal", func(t *testing.T) {
v1 := RandV2F[float32]()
v2 := RandV2F[float32]()
if v1.X == v2.X || v1.Y == v2.Y || v1.X == v1.Y || v2.X == v2.Y {
t.Errorf("Expected [%f, %f] not equal to each other or with [%f, %f]", v1.X, v1.Y, v2.X, v2.Y)
}
})
t.Run("generate 2 different random f64 vectors, shouldn't be equal", func(t *testing.T) {
v1 := RandV2F[float64]()
v2 := RandV2F[float64]()
if v1.X == v2.X || v1.Y == v2.Y || v1.X == v1.Y || v2.X == v2.Y {
t.Errorf("Expected [%f, %f] not equal to each other or with [%f, %f]", v1.X, v1.Y, v2.X, v2.Y)
}
})
t.Run("randomized vectors should be normalized", func(t *testing.T) {
v := RandV2F[float32]()
if !almostEqual[float64](math.Sqrt(float64((v.X*v.X)+(v.Y*v.Y))), 1.0, 1e-5) {
t.Errorf("Expected [%f, %f] to be normalized!", v.X, v.Y)
}
})
}
func Test_RandV3F(t *testing.T) {
t.Run("generate 2 different random f32 vectors, shouldn't be equal", func(t *testing.T) {
v1 := RandV3F[float32]()
v2 := RandV3F[float32]()
if v1.X == v2.X || v1.Y == v2.Y || v1.Z == v2.Z || v1.X == v1.Y || v1.X == v1.Z || v1.Y == v1.Z || v2.X == v2.Y || v2.X == v2.Z || v2.Y == v2.Z {
t.Errorf("Expected [%f, %f, %f] not equal to each other or with [%f, %f, %f]", v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z)
}
})
t.Run("generate 2 different random f64 vectors, shouldn't be equal", func(t *testing.T) {
v1 := RandV3F[float64]()
v2 := RandV3F[float64]()
if v1.X == v2.X || v1.Y == v2.Y || v1.Z == v2.Z || v1.X == v1.Y || v1.X == v1.Z || v1.Y == v1.Z || v2.X == v2.Y || v2.X == v2.Z || v2.Y == v2.Z {
t.Errorf("Expected [%f, %f, %f] not equal to each other or with [%f, %f, %f]", v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z)
}
})
t.Run("randomized vectors should be normalized", func(t *testing.T) {
v := RandV3F[float32]()
if !almostEqual[float64](math.Sqrt(float64((v.X*v.X)+(v.Y*v.Y)+(v.Z*v.Z))), 1.0, 1e-5) {
t.Errorf("Expected [%f, %f, %f] to be normalized!", v.X, v.Y, v.Z)
}
})
}