-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnone_test.go
76 lines (63 loc) · 1.77 KB
/
none_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
package enumerable_test
import (
"fmt"
"strings"
"testing"
E "github.com/darkhelmet/enumerable"
"github.com/stretchr/testify/assert"
)
func ExampleNone() {
words := strings.Fields("To be or not to be, that is the question!")
okay := E.None(words, func(s string) bool {
return len(s) > 8
})
fmt.Println(okay)
// Output: false
}
func TestNoneWorks(t *testing.T) {
ints := []int{2, 4, 6, 8}
aboveFive := E.None(ints, func(i int) bool {
return i > 5
})
assert.False(t, aboveFive)
negative := E.None(ints, func(i int) bool {
return i < 0
})
assert.True(t, negative)
}
func TestNoneRequiresSlice(t *testing.T) {
assert.Panics(t, func() {
E.None(1, "doesn't matter")
}, "requires a slice as the first arg")
}
func TestNoneRequiresAFunc(t *testing.T) {
assert.Panics(t, func() {
E.None([]int{1}, "not a func")
}, "requires a func as the second arg")
}
func TestNoneRequiresASingleArgFunc(t *testing.T) {
assert.Panics(t, func() {
E.None([]int{1}, func() {})
}, "requires a single arg function")
assert.Panics(t, func() {
E.None([]int{1}, func(i, j int) {})
}, "requires a single arg function")
}
func TestNoneRequiresASingleReturnFunc(t *testing.T) {
assert.Panics(t, func() {
E.None([]int{1}, func(i int) {})
}, "requires a single arg function")
assert.Panics(t, func() {
E.None([]int{1}, func(i int) (int, int) { return 1, 0 })
}, "requires a single arg function")
}
func TestNoneRequiresFuncToTakeSliceArg(t *testing.T) {
assert.Panics(t, func() {
E.None([]int{1}, func(s string) int { return 0 })
}, "requires the func to take the same type as the slice")
}
func TestNoneRequiresFuncToReturnABool(t *testing.T) {
assert.Panics(t, func() {
E.None([]int{1}, func(i int) int { return i })
}, "requires the func to take the same type as the slice")
}