-
Notifications
You must be signed in to change notification settings - Fork 11
/
compose_test.go
116 lines (98 loc) · 3.65 KB
/
compose_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package fp
import "testing"
func add1(x int) int {
return x + 1
}
func double(x int) int {
return x * 2
}
func TestCompose2_Example(t *testing.T) {
res := Compose2(add1, double)(0)
if res != 1 {
t.Error("Should perform right-to-left function composition of 2 functions. Received:", res)
}
}
func TestCompose3_Example(t *testing.T) {
res := Compose3(add1, double, add1)(0)
if res != 3 {
t.Error("Should perform right-to-left function composition of 3 functions. Received:", res)
}
}
func TestCompose4_Example(t *testing.T) {
res := Compose4(add1, double, add1, double)(0)
if res != 3 {
t.Error("Should perform right-to-left function composition of 4 functions. Received:", res)
}
}
func TestCompose5_Example(t *testing.T) {
res := Compose5(add1, double, add1, double, add1)(0)
if res != 7 {
t.Error("Should perform right-to-left function composition of 5 functions. Received:", res)
}
}
func TestCompose6_Example(t *testing.T) {
res := Compose6(add1, double, add1, double, add1, double)(0)
if res != 7 {
t.Error("Should perform right-to-left function composition of 6 functions. Received:", res)
}
}
func TestCompose7_Example(t *testing.T) {
res := Compose7(add1, double, add1, double, add1, double, add1)(0)
if res != 15 {
t.Error("Should perform right-to-left function composition of 7 functions. Received:", res)
}
}
func TestCompose8_Example(t *testing.T) {
res := Compose8(add1, double, add1, double, add1, double, add1, double)(0)
if res != 15 {
t.Error("Should perform right-to-left function composition of 8 functions. Received:", res)
}
}
func TestCompose9_Example(t *testing.T) {
res := Compose9(add1, double, add1, double, add1, double, add1, double, add1)(0)
if res != 31 {
t.Error("Should perform right-to-left function composition of 9 functions. Received:", res)
}
}
func TestCompose10_Example(t *testing.T) {
res := Compose10(add1, double, add1, double, add1, double, add1, double, add1, double)(0)
if res != 31 {
t.Error("Should perform right-to-left function composition of 10 functions. Received:", res)
}
}
func TestCompose11_Example(t *testing.T) {
res := Compose11(add1, double, add1, double, add1, double, add1, double, add1, double, add1)(0)
if res != 63 {
t.Error("Should perform right-to-left function composition of 11 functions. Received:", res)
}
}
func TestCompose12_Example(t *testing.T) {
res := Compose12(add1, double, add1, double, add1, double, add1, double, add1, double, add1, double)(0)
if res != 63 {
t.Error("Should perform right-to-left function composition of 12 functions. Received:", res)
}
}
func TestCompose13_Example(t *testing.T) {
res := Compose13(add1, double, add1, double, add1, double, add1, double, add1, double, add1, double, add1)(0)
if res != 127 {
t.Error("Should perform right-to-left function composition of 13 functions. Received:", res)
}
}
func TestCompose14_Example(t *testing.T) {
res := Compose14(add1, double, add1, double, add1, double, add1, double, add1, double, add1, double, add1, double)(0)
if res != 127 {
t.Error("Should perform right-to-left function composition of 14 functions. Received:", res)
}
}
func TestCompose15_Example(t *testing.T) {
res := Compose15(add1, double, add1, double, add1, double, add1, double, add1, double, add1, double, add1, double, add1)(0)
if res != 255 {
t.Error("Should perform right-to-left function composition of 15 functions. Received:", res)
}
}
func TestCompose16_Example(t *testing.T) {
res := Compose16(add1, double, add1, double, add1, double, add1, double, add1, double, add1, double, add1, double, add1, double)(0)
if res != 255 {
t.Error("Should perform right-to-left function composition of 16 functions. Received:", res)
}
}