forked from pannous/english-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_test.rb
executable file
·263 lines (220 loc) · 6.32 KB
/
list_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env ruby
$use_tree=false
$verbose =false
# $verbose=true
require_relative '../parser_test_helper'
class ListTest < ParserBaseTest # < EnglishParser
include ParserTestHelper
def test_type0
init "1 , 2 , 3"
assert_equals @parser.list, [1, 2, 3]
init "1,2,3"
assert_equals @parser.list, [1, 2, 3]
init "[1,2,3]"
assert_equals @parser.list, [1, 2, 3]
init "{1,2,3}"
assert_equals @parser.list, [1, 2, 3]
init "1,2 and 3"
assert_equals @parser.list, [1, 2, 3]
init "[1,2 and 3]"
assert_equals @parser.list, [1, 2, 3]
init "{1,2 and 3}"
assert_equals @parser.list, [1, 2, 3]
end
def test_list_methods
parse "invert [1,2,3]"
assert_equals result, [3, 2, 1] # YAY!!!
end
def test_error
assert_has_error "first item in 'hi,'you' is 'hi'" # quote not closed: 'hi,'y...
end
def test_last
assert("last item in 'hi','you' is equal to 'you'")
end
def test_select2
assert "first item in 'hi','you' is 'hi'"
assert "second item in 'hi','you' is 'you'"
assert "last item in 'hi','you' is 'you'"
end
def test_select3
# assert_equals parse("1st word of 'hi','you'"),"'hi'"
assert_equals parse("1st word of 'hi','you'"), "hi"
# assert "2nd word of 'hi','you' is 'you'"
# assert "3rd word of 'hi','my','friend' is 'friend'"
assert "1st word of 'hi','you' is 'hi'"
assert "2nd word of 'hi','you' is 'you'"
assert "3rd word of 'hi','my','friend' is 'friend'"
end
def test_select4
assert "first word of 'hi','you' is 'hi'"
assert "second word of 'hi','you' is 'you'"
assert "last word of 'hi','you' is 'you'"
end
def test_select5
skip
assert "numbers are 1,2,3. second number is 2"
assert "my friends are a,b and c. my second friend is b"
end
def test_select6
assert "last character of 'howdy' is 'y'"
assert "first character of 'howdy' is 'h'"
assert "second character of 'howdy' is 'o'"
end
def test_list_syntax
assert("1,2 is [1,2]")
assert("1,2 is {1,2}")
assert("1,2 == [1,2]")
assert("[1,2] is {1,2}")
assert("1,2 = [1,2]")
end
def test_list_syntax2
assert("1,2,3 is the same as [1,2,3]")
assert("1,2 and 3 is the same as [1,2,3]")
assert("1,2 and 3 are the same as [1,2,3]")
assert("1,2 and 3 is [1,2,3]")
end
def test_concatenation
parse "x is 1,2,3;y=4,5,6"
assert(variables['x'].value== [1, 2, 3]);
assert(variables['y'].value.count== 3);
init "x + y"
assert_equals z.length, 6
z=parse "x + y"
assert_equals z.length, 6
assert_equals result.length, 6
z=parse "x plus y"
assert_equals z.length, 6
end
def test_concatenation_plus
parse "x is 1,2;y=3,4"
z=parse "x plus y"
assert_equals z, [1, 2, 3, 4]
end
def test_concatenation2
parse "x is 1,2,3;y=4,5,6"
parse "x + y"
assert result.length==6
parse "z is x + y"
assert_equals(variables['z'], [1, 2, 3, 4,5,6]);
end
def test_concatenation2c
parse "x is 1,2
y is 3,4
z is x + y"
# // todo: remove newline!
assert_equals(variables['z'], [1, 2, 3, 4]);
end
def test_concatenation3
variables['x']= [1, 2];
variables['y']= [3, 4];
init "x + y == 1,2,3,4"
@parser.condition
assert("x + y == 1,2,3,4");
assert_equals(parse("x plus y"), [1, 2].plus([3, 4]))
assert("x plus y == [1,2,3,4]");
# assert("x and y == [1,2,3,4]")
end
def test_concatenation4
# Ambiguous: 'and' also indicates I don't know what 1 and 1 = 2, NOT [1,1] OK?
# and : logic, list and 'plus'?? no way!!
assert("1,2 and 3 == 1,2,3")
# assert_equals(parse("1 and 1"),2) # too complicated!!
# assert("1 and 1 == 2")
# init "x and y"
# @parser.algebra
# init "true and true"
# @parser.condition
end
def test_type1
init "class of 1,2,3"
@parser.evaluate_property
assert_equals result, Array
init "class of [1,2,3]"
@parser.expressions
assert_equals result, Array
skip
parse "class of 1,2,3"
assert_equals result, Array
end
def test_type2
parse "x=1,2,3;class of x"
assert_equals result, Array
end
def test_type
parse "x=1,2,3;"
# $verbose=true
assert "type of x is Array"
end
def test_type3
parse "x be 1,2,3;y= class of x"
assert variables['y']==Array
assert_equals variables['x'].type, Array
assert_equals variables['x'].value.class, Array
assert_equals variables['x'].value.kind, Array
assert_equals variables['y'], Array
assert("y is a Array")
assert("y is an Array")
assert("y is Array")
assert("Array == class of x")
assert("class of x is Array")
assert("kind of x is Array")
assert("type of x is Array")
end
def test_type4
variables['x']=Variable.new name:'x',value: [1, 2, 3]
assert("class of x is Array")
assert("kind of x is Array")
assert("type of x is Array")
end
def test_length
variables['xs']=Variable.new name:'xs',value: [1, 2, 3]
assert("length of xs is 3")
assert("size of xs is 3")
assert("count of xs is 3")
# assert("number of elements in xs is 3")
# assert("number of items in xs is 3")
end
def test_map #needs auto-map !!!
# $auto_map=true
assert_equals parse("square [1,2,3]"), [1, 4, 9]
assert_equals parse("square [1,2 and 3]"), [1, 4, 9]
end
def test_map2 # list vs params !
assert("square of 1,2 and 3 == 1,4,9")
assert_equals parse("square 1,2,3"), [1, 4, 9] #needs Array.method_missing (auto-map) !!!
assert_equals parse("square 1,2 and 3"), [1, 4, 9]
end
def test_map22 # list vs params !
assert_result_is ("square 1,2 and 3"), [1, 4, 9]
assert("square of [1,2 and 3] equals 1,4,9")
parse("assert square of [1,2 and 3] equals 1,4,9")
skip
assert("square 1,2 and 3 == 1,4,9")
end
def test_map3
skip
assert("square every number in 1,2,3 ==1,4,9")
assert("add one to every number in 1,2,3 ==2,3,4")
assert("square every number in 1,'a',3 ==1,9")
end
def test_hasht
init "{1,2,3}"
assert_equals @parser.list, [1, 2, 3]
init "{a:1,b:2,c:3}"
assert_equals @parser.json_hash, {a: 1, b: 2, c: 3}
end
end
#
# class ListTest < ParserTest
#
# def initialize args
# @testParser=ListTestParser.new
# super args
# end
#
# def test_current
# @testParser.current
# end
#
# end