-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtest_basic_jetta.metta
91 lines (79 loc) · 2.2 KB
/
test_basic_jetta.metta
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
!(import! &self compile)
; testing evaluation of a simple expression
; in a new jetta space using textual api
!(assertEqual
(jetta (new-jetta-space) "(+ 1 2)")
3)
; creating a space for repetitive use
!(bind! &jspace (new-jetta-space))
; passing text code of a typed function definition
!(jetta &jspace
"(: foo (-> Int Int Int))
(= (foo $x $y) (+ $x $y 1))")
; checking that the function can be evaluated multiple times,
; and it doesn't block evaluation of other expressions
!(assertEqual
(jetta &jspace "(foo 11 2)")
14)
!(assertEqual
(jetta &jspace "(foo 11 3)")
15)
!(assertEqual
(jetta &jspace "(+ 11 12)")
23)
; checking that we can pass an atom to `jetta`;
; `(foo 11 4)` is not reduced in this case, because
; `foo` was not defined and passed to `jetta` in a text code;
; FIXME? Should `jetta` accept the code as `Atom` type to
; avoid reducing such expressions in MeTTa?
!(assertEqual
(jetta &jspace (foo 11 4))
16)
; Testing errors
!(assertEqualToResult
(case (jetta "WRON SPACE" "(foo 11 4)")
(((Error $1 (JettaCompileError $2)) $2)))
("Status code: 500"))
; error: cannot resolve symbol
!(assertEqual
(< 0
((py-dot
(case (jetta &jspace "(foof 11 4)")
(((Error $1 (JettaCompileError $2)) $2)))
"find") "CannotResolveSymbol"))
True)
; TODO: fix the behavior (one or multiple results)
;(jetta &jspace
; "(foo 11 3)
; (foo 11 4)")
; TODO: type inference doesn't work in this simple case
;!(jetta &jspace
; "(= (goo $x) (+ $x 1))
; (goo 1)")
; checking if recursion with type definitions work
; also checking `-` in names
; TODO: use <= and /
!(assertEqual
(jetta &jspace
"(: log-int (-> Int Int))
(= (log-int $x)
(if (== $x 1) 0 (+ 1 (log-int (- $x 1))))
)
(log-int 8)")
7)
; checking recursion with type inference
!(jetta &jspace
"(= (fact $n)
(if (== $n 0) 1 (* $n (fact (- $n 1)))))")
!(assertEqual
(jetta &jspace "(fact 10)")
3628800)
; Can type definitions be loaded separately?
; ! (jetta &jspace "(: foo (-> Int Int Int))")
; ! (jetta &jspace "(= (foo $x $y) (+ $x $y 1))")
; Doesn't work
;! (jetta &jspace "(: foo (-> Int Int Int))
; (= (foo 0 0) 0)
; (foo 0 0)
; ")
; TODO: add floats and mixed