-
Notifications
You must be signed in to change notification settings - Fork 3
/
clamp_test.go
62 lines (58 loc) · 926 Bytes
/
clamp_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 math
import (
"testing"
)
func TestClamp(t *testing.T) {
t.Parallel()
tests := []struct {
f, low, high, expected float32
}{
{
f: 0.5,
low: 0,
high: 1,
expected: 0.5,
},
{
f: -0.5,
low: 0,
high: 1,
expected: 0,
},
{
f: 1.5,
low: 0,
high: 1,
expected: 1,
},
{
f: 1.5,
low: 1,
high: 2,
expected: 1.5,
},
{
f: 0.5,
low: 1,
high: 2,
expected: 1,
},
{
f: 2.5,
low: 1,
high: 2,
expected: 2,
},
{
f: NaN(),
low: 1,
high: 2,
expected: NaN(),
},
}
for i, test := range tests {
if r := Clamp(test.f, test.low, test.high); r != test.expected && !(IsNaN(test.expected) && IsNaN(r)) {
t.Errorf("[%d] Clamp(%f,%f,%f) = %f, want %f", i, test.f, test.low, test.high, r, test.expected)
}
}
}