-
Notifications
You must be signed in to change notification settings - Fork 2
/
functional_test.go
53 lines (40 loc) · 1002 Bytes
/
functional_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 functional
import "testing"
func TestMap(t *testing.T) {
inputList := []int{1, 2, 3}
square := func(x interface{}) interface{} {
return x.(int) * x.(int)
}
expected := []int{1, 4, 9}
actual := Map(square, inputList)
for i, e := range expected {
if e != actual[i] {
t.Errorf("expected %v != actual %v", expected, actual)
}
}
}
func TestFilter(t *testing.T) {
inputList := []int{1, 2, 3}
modulotwo := func(x interface{}) bool {
return x.(int)%2 == 0
}
expected := []int{2}
actual := Filter(modulotwo, inputList)
for i, e := range expected {
if e != actual[i] {
t.Errorf("expected %v != actual %v", expected, actual)
}
}
}
func TestFoldl(t *testing.T) {
inputList := []int{1, 2, 3}
funcFoldl := func(x interface{}, acc interface{}) interface{} {
return x.(int) + acc.(int)
}
expected := 6
accumulator := 0
actual := Foldl(funcFoldl, inputList, accumulator)
if expected != actual {
t.Errorf("expected %v != actual %v", expected, actual)
}
}