-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptional_filter_test.go
61 lines (50 loc) · 1.06 KB
/
optional_filter_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
package opt_test
import (
"github.com/reiver/go-opt"
"testing"
)
func TestOptional_Filter_int(t *testing.T) {
tests := []struct{
Optional opt.Optional[int]
Expected opt.Optional[int]
}{
{
Optional: opt.Nothing[int](),
Expected: opt.Nothing[int](),
},
{
Optional: opt.Something[int](-2),
Expected: opt.Something[int](-2),
},
{
Optional: opt.Something[int](-1),
Expected: opt.Nothing[int](),
},
{
Optional: opt.Something[int](0),
Expected: opt.Something[int](0),
},
{
Optional: opt.Something[int](1),
Expected: opt.Nothing[int](),
},
{
Optional: opt.Something[int](2),
Expected: opt.Something[int](2),
},
}
for testNumber, test := range tests {
fn := func(value int) bool {
return 0 == (value % 2)
}
actual := test.Optional.Filter(fn)
expected := test.Expected
if expected != actual {
t.Errorf("For test #%d, the actual value is not what was expected.", testNumber)
t.Logf("EXPECTED: %#v", expected)
t.Logf("ACTUAL: %#v", actual)
/////////////// CONTINUE
continue
}
}
}