-
Notifications
You must be signed in to change notification settings - Fork 2
/
f_test.go
48 lines (45 loc) · 1014 Bytes
/
f_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
package xirho_test
import (
"math"
"testing"
"github.com/zephyrtronium/xirho"
)
func TestPtIsValid(t *testing.T) {
succeed := []xirho.Pt{
{X: math.Nextafter(math.Inf(0), 0)},
{Y: math.Nextafter(math.Inf(0), 0)},
{Z: math.Nextafter(math.Inf(0), 0)},
{C: 0},
{C: math.Nextafter(0, 1)},
{C: 1},
{C: math.Nextafter(1, 0)},
{X: math.Nextafter(math.Inf(0), 0), Y: math.Nextafter(math.Inf(-1), 0)},
}
fail := []xirho.Pt{
{C: math.Nextafter(0, -1)},
{C: math.Nextafter(1, 2)},
}
// Check non-finite values exhaustively.
vs := []float64{0, math.NaN(), math.Inf(0), math.Inf(-1)}
for _, x := range vs {
for _, y := range vs {
for _, z := range vs {
for _, c := range vs {
if x != 0 || y != 0 || z != 0 || c != 0 {
fail = append(fail, xirho.Pt{X: x, Y: y, Z: z, C: c})
}
}
}
}
}
for _, p := range succeed {
if !p.IsValid() {
t.Error(p, "not reported valid")
}
}
for _, p := range fail {
if p.IsValid() {
t.Error(p, "reported valid")
}
}
}