-
Notifications
You must be signed in to change notification settings - Fork 11
/
some_test.go
53 lines (40 loc) · 1.52 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package fp
import (
"testing"
)
func TestSome_TrueExmple(t *testing.T) {
res := Some(func(x int) bool { return x > 0 })([]int{-1, -2, 3})
if res != true {
t.Error("Some should return true as at least one element match the condition. Received:", res)
}
}
func TestSome_FalseExmple(t *testing.T) {
res := Some(func(x int) bool { return x < 0 })([]int{1, 2, 3})
if res != false {
t.Error("Some should return false as none of the element match the condition. Received:", res)
}
}
func TestSomeWithIndex_TrueExmple(t *testing.T) {
res := SomeWithIndex(func(x int, i int) bool { return x+i > 0 })([]int{-10, -20, -1})
if res != true {
t.Error("Some should return true as at least one element match the condition. Received:", res)
}
}
func TestSomeWithIndex_FalseExmple(t *testing.T) {
res := SomeWithIndex(func(x int, i int) bool { return x+i < 0 })([]int{1, 2, 3})
if res != false {
t.Error("Some should return false as none of the element match the condition. Received:", res)
}
}
func TestSomeWithSlice_TrueExmple(t *testing.T) {
res := SomeWithSlice(func(x int, i int, xs []int) bool { return x+i-xs[0] > 0 })([]int{-1, -20, -2})
if res != true {
t.Error("Some should return true as at least one element match the condition. Received:", res)
}
}
func TestSomeWithSlice_FalseExmple(t *testing.T) {
res := SomeWithSlice(func(x int, i int, xs []int) bool { return x+i+xs[0] < 0 })([]int{1, 2, 3, -4})
if res != false {
t.Error("Some should return false as none of the element match the condition. Received:", res)
}
}