Skip to content

Commit 7fc4a54

Browse files
committed
Add isDelta test
1 parent 4a6ef15 commit 7fc4a54

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

gfx_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package gfx
2+
3+
import (
4+
"math"
5+
"testing"
6+
)
7+
8+
func inDelta(t *testing.T, expected, actual, delta float64) bool {
9+
t.Helper()
10+
11+
if math.IsNaN(expected) && math.IsNaN(actual) {
12+
return true
13+
}
14+
15+
if math.IsNaN(expected) {
16+
t.Error("Expected must not be NaN")
17+
return false
18+
}
19+
20+
if math.IsNaN(actual) {
21+
t.Errorf("Expected %v with delta %v, but was NaN", expected, delta)
22+
return false
23+
}
24+
25+
if dt := expected - actual; dt < -delta || dt > delta {
26+
t.Errorf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt)
27+
return false
28+
}
29+
30+
return true
31+
}

0 commit comments

Comments
 (0)