-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArray_test.go
40 lines (32 loc) · 845 Bytes
/
Array_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
package func_go
import (
"fmt"
"testing"
)
func TestInt(t *testing.T) {
res := NewArray(1).
Map(func(i Any) Any { return i.(int) * 2 }).
Reduce(func(a Any, b Any) Any { return a.(int) + b.(int) })
if res != 2 {
t.Error("Expected 2, got ", res)
}
}
func TestArray(t *testing.T) {
res := NewArray([]int{1, 2, 3, 4, 5}).
Map(func(i Any) Any { return i.(int) * 2 }).
Reduce(func(a Any, b Any) Any { return a.(int) + b.(int) })
if res != 30 {
t.Error("Expected ArrayOps{2, 4, 6, 8, 10}, got ", res)
}
}
func TestFilter(t *testing.T) {
res := NewArray([]int{1, 2, 3, 4, 5}).
Filter(func(i Any) bool { return i.(int)%2 == 0 })
if len(*res) != 2 {
t.Error("Expected ArrayOps{2, 4, 6, 8, 10}, got ", res)
}
}
func TestForEach(t *testing.T) {
NewArray([]int{1, 2, 3, 4, 5}).
ForEach(func(i Any) { fmt.Println(i) })
}