forked from pannous/english-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_test.rb
executable file
·112 lines (93 loc) · 2.3 KB
/
tree_test.rb
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
#!/usr/bin/env ruby
# encoding: utf-8
# $use_tree=true
$use_tree=false
require_relative '../parser_test_helper'
class TreeTest < ParserBaseTest
include ParserTestHelper
def test_algebra1
assert_result_is "3 minus one",2
init "4½"
assert_equals @parser.fraction,4.5
init "4½+3½"
@parser.do_interpret!
assert_equals @parser.algebra,8
assert_result_is "4½+3½","8"
end
def test_method4
init "how to integrate a bug
test
ok"
assert @parser.method_definition
end
def _test_block
init "let the initial value of I be x;\n
step size is the length of the interval,
divided by the number of steps\n
var x = 8;"
@parser.block
end
def _test_while
@variableValues[:i]=0;
@variableValues[:y]=5;
parse "while i is smaller or less then y do
increase i by 4;
done"
assert_equals @variableValues[:i],8
end
def _test_while2
init "while i is smaller or less then y do
evaluate the function at point I
add the result to the sum
increase I by the step size
done"
@parser.looper
end
def _test_setter3
init "step size is the length of the interval, divided by the number of steps"
@parser.setter
end
def test_looper
skip
parse "i=1;y=2;"
init "while i is smaller or equal y do\ni++\nend"
@parser.loops
init "while i is smaller or equal than y do\ni++\nend"
@parser.loops
end
def test_then_typo
# parse "i=1;y=2;"
skip
# todo 1) throw, don't loop 2) throw yawn UP!
parse "while i is smaller or equal y then do\nyawn\nend"
skip
parse "while i is smaller or equal then y do\nyawn\nend"
end
def test_method_call
skip
init "evaluate the function at point I"
# @parser.method_call
#action
end
def test_algebra_NOW
skip "test_algebra_NOW, DONT SKIP!" # todo !!
assert_result_is "1+3/4.0","1¾"
# 1.0 noo
assert_result_is "1.0+3/4.0","1¾"
# 4.0
end
def test_algebra
# s "2* ( 3 + 10 )"
init "2*(3+10)"
puts "Parsed input as #{ok}!"
assert_equals ok,26
skip if not $use_tree
current_node=interpretation.root
full_value=current_node.full_value
val=eval(full_value)
assert_equals val,26
val=current_node.eval_node()
assert_equals val,26
end
end