-
Notifications
You must be signed in to change notification settings - Fork 9
/
every_test.go
32 lines (26 loc) · 951 Bytes
/
every_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
package goterators
import (
"fmt"
"testing"
)
func TestEveryValid(t *testing.T) {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
expectedValid := true
everyValid := Every(testSource, func(item int) bool { return item <= 20 })
if everyValid != expectedValid {
t.Errorf("Expected = %v , got = %v", expectedValid, everyValid)
}
}
func TestEveryNotValid(t *testing.T) {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
expectedValid := false
everyValid := Every(testSource, func(item int) bool { return item%2 == 0 })
if everyValid != expectedValid {
t.Errorf("Expected = %v , got = %v", expectedValid, everyValid)
}
}
func ExampleEvery() {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
everyValid := Every(testSource, func(item int) bool { return item <= 20 })
fmt.Println("Every: ", everyValid)
}