-
Notifications
You must be signed in to change notification settings - Fork 2
/
number_test.go
84 lines (77 loc) · 2.25 KB
/
number_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
package verify_test
import (
"math"
"testing"
"github.com/fluentassert/verify"
)
func TestNumber(t *testing.T) {
t.Run("InDelta", func(t *testing.T) {
t.Run("Near", func(t *testing.T) {
msg := verify.Number(0.0).InDelta(1, 10)
assertPassed(t, msg)
})
t.Run("Far", func(t *testing.T) {
msg := verify.Number(0.0).InDelta(-100, 10)
assertFailed(t, msg, "absolute error (distance) between numbers is greater than delta")
})
})
t.Run("NotInDelta", func(t *testing.T) {
t.Run("Near", func(t *testing.T) {
msg := verify.Number(0.0).NotInDelta(-1.0, 10)
assertFailed(t, msg, "absolute error (distance) between numbers is lesser or equal than delta")
})
t.Run("Far", func(t *testing.T) {
msg := verify.Number(0.0).NotInDelta(100, 10)
assertPassed(t, msg)
})
})
t.Run("InEpsilon", func(t *testing.T) {
t.Run("Near", func(t *testing.T) {
msg := verify.Number(1.0).InEpsilon(1, 2)
assertPassed(t, msg)
})
t.Run("Far", func(t *testing.T) {
msg := verify.Number(100.0).InEpsilon(1, 2)
assertFailed(t, msg, "relative error between numbers is greater than epsilon")
})
})
t.Run("NotInEpsilon", func(t *testing.T) {
t.Run("Near", func(t *testing.T) {
msg := verify.Number(0.0).NotInEpsilon(1, 2)
assertFailed(t, msg, "relative error between numbers is lesser or equal than epsilon")
})
t.Run("Far", func(t *testing.T) {
msg := verify.Number(100.0).NotInEpsilon(1, 2)
assertPassed(t, msg)
})
})
t.Run("InvalidInputs", func(t *testing.T) {
for _, fn := range []func() verify.FailureMessage{
func() verify.FailureMessage {
return verify.Number(math.NaN()).InDelta(1, 2)
},
func() verify.FailureMessage {
return verify.Number(1.0).NotInDelta(math.NaN(), 2)
},
func() verify.FailureMessage {
return verify.Number(1.0).InDelta(1, -2)
},
func() verify.FailureMessage {
return verify.Number(math.NaN()).InEpsilon(1, 2)
},
func() verify.FailureMessage {
return verify.Number(1.0).NotInEpsilon(math.NaN(), 2)
},
func() verify.FailureMessage {
return verify.Number(1.0).InEpsilon(1, -2)
},
func() verify.FailureMessage {
return verify.Number(1.0).InEpsilon(0.0, 2)
},
} {
if msg := fn(); msg == "" {
t.Error("should fail but passed")
}
}
})
}