-
Notifications
You must be signed in to change notification settings - Fork 11
/
every_test.go
53 lines (40 loc) · 1.54 KB
/
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
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 TestEvery_TrueExample(t *testing.T) {
res := Every(func(x int) bool { return x > 0 })([]int{1, 2, 3})
if res != true {
t.Error("Every should return true as all elements match the condition. Received:", res)
}
}
func TestEvery_FalseExample(t *testing.T) {
res := Every(func(x int) bool { return x < 0 })([]int{-1, -2, 3})
if res != false {
t.Error("Every should return false if at least one element does not match the condition. Received:", res)
}
}
func TestEveryWithIndex_TrueExample(t *testing.T) {
res := EveryWithIndex(func(x int, i int) bool { return x+i > 0 })([]int{1, 2, -1})
if res != true {
t.Error("Every should return true as all elements match the condition. Received:", res)
}
}
func TestEveryWithIndex_FalseExample(t *testing.T) {
res := EveryWithIndex(func(x int, i int) bool { return x+i < 0 })([]int{-1, -2, 3})
if res != false {
t.Error("Every should return false if at least one element does not match the condition. Received:", res)
}
}
func TestEveryWithSlice_TrueExample(t *testing.T) {
res := EveryWithSlice(func(x int, i int, xs []int) bool { return x+i+xs[0] > 0 })([]int{1, 2, -2})
if res != true {
t.Error("Every should return true as all elements match the condition. Received:", res)
}
}
func TestEveryWithSlice_FalseExample(t *testing.T) {
res := EveryWithSlice(func(x int, i int, xs []int) bool { return x+i+xs[0] < 0 })([]int{-1, -2, 3})
if res != false {
t.Error("Every should return false if at least one element does not match the condition. Received:", res)
}
}