-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.htm
112 lines (100 loc) · 3.26 KB
/
Test.htm
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
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.8.0/jasmine.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.8.0/jasmine.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.8.0/jasmine-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.8.0/boot.min.js"></script>
<script src="Jisp.js"></script>
</head>
<body>
<script>
describe('Expressions', function () {
it('Function', function () {
expect(Jisp.Eval(
[
["Function",
["x", "y"],
["*",
["Get", "x"],
["Get", "y"]
]
],
2,
5
]
)).toEqual(10);
expect(Jisp.Eval(
[
["Set", "main",
["Function", ["name"],
["Print", ["+", "Hello ", ["Get", "name"]]]
]
],
"World"
]
)).toEqual("Hello World");
});
it('For', function () {
expect(Jisp.Eval(
["For", "i", 0, 10, 2,
["Get", "i"]
]
)).toEqual([0, 2, 4, 6, 8, 10]);
});
it('While', function () {
expect(Jisp.Eval(
[
["Set", "i", 0],
["While",
["<",
["Get", "i"],
3],
["++", "i"]
]
]
)).toEqual([0, [0, 1, 2]]);
});
it('If', function () {
expect(Jisp.Eval(["If", true, 1, 2])).toEqual(1);
expect(Jisp.Eval(["If", false, 1, 2])).toEqual(2);
});
it('Variables', function () {
expect(Jisp.Eval(
[
["Set", "i", 1],
["Get", "i"],
]
)).toEqual([1, 1]);
});
it('Operators', function () {
expect(Jisp.Eval(["+", 1, 2])).toEqual(3);
expect(Jisp.Eval(["-", 1, 2])).toEqual(-1);
expect(Jisp.Eval(["/", 1, 2])).toEqual(0.5);
expect(Jisp.Eval(["*", 1, 2])).toEqual(2);
expect(Jisp.Eval(
[
["Set", "i", 0],
["++", "i"],
["++", "i"],
["++", "i"],
["--", "i"],
["Get", "i"]
]
)).toEqual([0, 0, 1, 2, 3, 2]);
});
it('Library', function () {
expect(Jisp.Eval(
["Print",
["+",
["*", 2, 3],
["Sin",
["/", 3.14, 2]
]
]
]
)).toEqual(6.9999996829318345);
});
});
</script>
</body>
</html>