-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreduce_test.go
46 lines (43 loc) · 1.22 KB
/
reduce_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
package combinator
import (
"context"
"testing"
)
func TestReduce(t *testing.T) {
basis := Basis{
Combinator{
Name: "I",
Arguments: []string{"x"},
Definition: "x",
},
Combinator{
Name: "R",
Arguments: []string{"x", "y"},
Definition: "yx",
},
}
tests := map[string]string{
"Ix": "x",
"Rxy": "yx",
"Ryx": "xy",
"RIxy": "xIy",
"II": "I",
"x(Ix)": "xx",
"x(I(Ix))x": "xxx",
}
for statement, expectedResult := range tests {
t.Run(statement, func(t *testing.T) {
tree := parse(statement)
reducedNormal, _ := reduce(context.Background(), tree, basis, false, 0)
actualResultNormal := unparse(reducedNormal)
reducedApplicative, _ := reduce(context.Background(), tree, basis, true, 0)
actualResultApplicative := unparse(reducedApplicative)
if expectedResult != actualResultNormal {
t.Errorf("parsed statement %s incorrectly with normal order, expected %s but got %s", statement, expectedResult, actualResultNormal)
}
if expectedResult != actualResultApplicative {
t.Errorf("parsed statement %s incorrectly with applicative order, expected %s but got %s", statement, expectedResult, actualResultApplicative)
}
})
}
}