forked from ledongthuc/goterators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsome_test.go
34 lines (28 loc) · 940 Bytes
/
some_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
package goterators
import (
"fmt"
"testing"
)
func TestSomeValid(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 := Some(testSource, func(item int) bool { return item%2 == 0 })
if everyValid != expectedValid {
t.Errorf("Expected = %v , got = %v", expectedValid, everyValid)
}
}
func TestSomeNotValid(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 > 20 })
if everyValid != expectedValid {
t.Errorf("Expected = %v , got = %v", expectedValid, everyValid)
}
}
func ExampleSome() {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
result := Some(testSource, func(item int) bool {
return item%2 == 0
})
fmt.Println("Some: ", result)
}