forked from erh/scheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_test.go
47 lines (35 loc) · 937 Bytes
/
exec_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
package scheme
import (
"testing"
"github.com/stretchr/testify/assert"
)
func evalTest(t *testing.T, s string, correct interface{}, scope Scope) {
x, err := Parse(s)
if err != nil {
t.Fatalf("%s %s", err, s)
}
y, err := Eval(x, scope)
if err != nil {
t.Fatalf("%s %s", err, s)
}
assert.Equal(t, correct, y.Primitive())
}
func TestPriimitives(t *testing.T) {
scope := Scope{}
evalTest(t, "5", 5.0, scope)
evalTest(t, "5.3", 5.3, scope)
evalTest(t, "\"abc\"", "abc", scope)
}
func TestMath1(t *testing.T) {
scope := Scope{}
evalTest(t, "(+ 1 2.1)", 3.1, scope)
evalTest(t, "(+ 1 2.1 -1)", 2.1, scope)
evalTest(t, "(+ 1 2.1 1.1)", 4.2, scope)
evalTest(t, "(* 2 2.1)", 4.2, scope)
evalTest(t, "(* 2 2.1 2)", 8.4, scope)
v := 1501.0
scope["raw"] = &Value{Float: &v}
evalTest(t, "(- raw 1100)", 401.0, scope)
evalTest(t, "(/ (- raw 1100) 10)", 40.1, scope)
//evalTest(t, "(max -3.1 0.1)", 0.1, scope)
}