-
Notifications
You must be signed in to change notification settings - Fork 1
/
testutils_test.go
56 lines (49 loc) · 1.6 KB
/
testutils_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
package vmath
import (
"testing"
"github.com/stretchr/testify/assert"
)
func AssertFloat(t *testing.T, expected, actual float32) {
t.Helper()
assert.InDelta(t, expected, actual, float64(eps))
}
func AssertVec2f(t *testing.T, expected, actual Vec2f) {
t.Helper()
delta := float32(eps)
diff := expected.Sub(actual)
if diff[0] < -delta || diff[0] > delta || diff[1] < -delta || diff[1] > delta {
t.Errorf("Expected: %v, was: %v; Max difference is %v, but was %v", expected, actual, delta, diff)
}
}
func AssertVec3f(t *testing.T, expected, actual Vec3f) {
t.Helper()
delta := float32(eps)
diff := expected.Sub(actual)
if diff[0] < -delta || diff[0] > delta ||
diff[1] < -delta || diff[1] > delta ||
diff[2] < -delta || diff[2] > delta {
t.Errorf("Expected: %v, was: %v; Max difference is %v, but was %v", expected, actual, delta, diff)
}
}
func AssertVec4f(t *testing.T, expected, actual Vec4f) {
t.Helper()
delta := float32(eps)
diff := expected.Sub(actual)
if diff[0] < -delta || diff[0] > delta ||
diff[1] < -delta || diff[1] > delta ||
diff[2] < -delta || diff[2] > delta ||
diff[3] < -delta || diff[3] > delta {
t.Errorf("Expected: %v, was: %v; Max difference is %v, but was %v", expected, actual, delta, diff)
}
}
func AssertQuat(t *testing.T, expected, actual Quat) {
t.Helper()
delta := float32(eps)
diff := expected.Sub(actual)
if diff.W < -delta || diff.W > delta ||
diff.X < -delta || diff.X > delta ||
diff.Y < -delta || diff.Y > delta ||
diff.Z < -delta || diff.Z > delta {
t.Errorf("Expected: %v, was: %v; Max difference is %v, but was %v", expected, actual, delta, diff)
}
}