-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice_test.go
57 lines (52 loc) · 1013 Bytes
/
slice_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
package test
import (
"testing"
"github.com/stretchr/testify/assert"
)
var (
testResult3 = 33.04
testResult4 = 0.11
)
var findFirstTests = []struct {
ss []float64
expression func(value float64) bool
expected *float64
}{
{
nil,
func(value float64) bool { return value == 1.5 },
nil,
},
{
[]float64{},
func(value float64) bool { return value == 0.1 },
nil,
},
{
[]float64{0.0, 1.5, 3.2},
func(value float64) bool { return value == 9.99 },
nil,
},
{
[]float64{5.4, 6.98, 4.987, 33.04},
func(value float64) bool { return value == 33.04 },
&testResult3,
},
{
[]float64{9.0, 0.11, 150.44, 33.04},
func(value float64) bool { return value == 0.11 },
&testResult4,
},
}
func TestFindFirst(t *testing.T) {
for _, test := range findFirstTests {
t.Run("", func(t *testing.T) {
result := FindFirst(test.ss, test.expression)
if result == nil {
assert.Nil(t, test.expected)
} else {
assert.InEpsilon(t, *test.expected, *result, 0)
}
})
}
}