|
| 1 | +package fp |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestCompose2_Example(t *testing.T) { |
| 9 | + res := Compose2( |
| 10 | + Map(func(x int) int { return x + 2 }), |
| 11 | + Filter(func(x int) bool { return x > 0 }))([]int{1, 2, 3, -1}) |
| 12 | + expected := []int{3, 4, 5} |
| 13 | + |
| 14 | + if reflect.DeepEqual(res, expected) == false { |
| 15 | + t.Error("Should perform right-to-left function composition of two functions. Received:", res) |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +func TestCompose3_Example(t *testing.T) { |
| 20 | + res := Compose3( |
| 21 | + Map(func(x int) int { return x + 2 }), |
| 22 | + Map(func(x int) int { return x + 2 }), |
| 23 | + Filter(func(x int) bool { return x > 0 }))([]int{1, 2, 3, -1}) |
| 24 | + expected := []int{5, 6, 7} |
| 25 | + |
| 26 | + if reflect.DeepEqual(res, expected) == false { |
| 27 | + t.Error("Should perform right-to-left function composition of two functions. Received:", res) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +func TestCompose4_Example(t *testing.T) { |
| 32 | + res := Compose4( |
| 33 | + Map(func(x int) int { return x + 2 }), |
| 34 | + Map(func(x int) int { return x + 2 }), |
| 35 | + Map(func(x int) int { return x + 2 }), |
| 36 | + Filter(func(x int) bool { return x > 0 }))([]int{1, 2, 3, -1}) |
| 37 | + expected := []int{7, 8, 9} |
| 38 | + |
| 39 | + if reflect.DeepEqual(res, expected) == false { |
| 40 | + t.Error("Should perform right-to-left function composition of two functions. Received:", res) |
| 41 | + } |
| 42 | +} |
0 commit comments