rufus-decision 0.9 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +10 -0
- data/CREDITS.txt +7 -0
- data/README.txt +13 -3
- data/lib/rufus/decision.rb +484 -484
- data/lib/rufus/hashes.rb +143 -108
- data/lib/rufus-decision.rb +3 -0
- data/test/decision_0_test.rb +293 -293
- data/test/decision_1_test.rb +38 -38
- data/test/dmixin.rb +28 -28
- data/test/eval_test.rb +12 -12
- metadata +13 -6
data/test/decision_0_test.rb
CHANGED
@@ -13,15 +13,15 @@ require 'dmixin'
|
|
13
13
|
|
14
14
|
|
15
15
|
class DecisionTest < Test::Unit::TestCase
|
16
|
-
|
16
|
+
include DecisionTestMixin
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
#def setup
|
19
|
+
#end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
#def teardown
|
22
|
+
#end
|
23
23
|
|
24
|
-
|
24
|
+
CSV0 = \
|
25
25
|
"""
|
26
26
|
,,
|
27
27
|
in:fx,in:fy,out:fz
|
@@ -31,22 +31,22 @@ c,d,1
|
|
31
31
|
e,f,2
|
32
32
|
"""
|
33
33
|
|
34
|
-
|
34
|
+
def test_csv_0
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
wi = {
|
37
|
+
"fx" => "c",
|
38
|
+
"fy" => "d"
|
39
|
+
}
|
40
|
+
do_test(CSV0, wi, {}, { "fz" => "1" }, false)
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
wi = {
|
43
|
+
"fx" => "a",
|
44
|
+
"fy" => "d"
|
45
|
+
}
|
46
|
+
do_test(CSV0, wi, {}, { "fz" => nil }, false)
|
47
|
+
end
|
48
48
|
|
49
|
-
|
49
|
+
CSV0B = \
|
50
50
|
"""
|
51
51
|
|
52
52
|
in:fx,in:fy,out:fz
|
@@ -56,163 +56,163 @@ c,d,1
|
|
56
56
|
e,f,2
|
57
57
|
"""
|
58
58
|
|
59
|
-
|
59
|
+
def test_0b
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
wi = {
|
62
|
+
"fx" => "c",
|
63
|
+
"fy" => "d"
|
64
|
+
}
|
65
|
+
do_test(CSV0B, wi, {}, { "fz" => "1" }, false)
|
66
|
+
end
|
67
67
|
|
68
|
-
|
68
|
+
# test 1 moved to decision_1_test.rb
|
69
69
|
|
70
|
-
|
70
|
+
CSV2 = \
|
71
71
|
"""
|
72
72
|
in:fx, in:fy, out:fz
|
73
73
|
,,
|
74
|
-
a,
|
75
|
-
c,
|
76
|
-
e,
|
74
|
+
a, b, 0
|
75
|
+
c, d, 1
|
76
|
+
e, f, 2
|
77
77
|
"""
|
78
78
|
|
79
|
-
|
79
|
+
def test_2
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
wi = {
|
82
|
+
"fx" => "c",
|
83
|
+
"fy" => "d"
|
84
|
+
}
|
85
|
+
do_test(CSV2, wi, {}, { "fz" => "1" }, false)
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
wi = {
|
88
|
+
"fx" => "a",
|
89
|
+
"fy" => "d"
|
90
|
+
}
|
91
|
+
do_test(CSV2, wi, {}, { "fz" => nil }, false)
|
92
|
+
end
|
93
93
|
|
94
|
-
|
94
|
+
CSV3 = \
|
95
95
|
"""
|
96
96
|
in:weather, in:month, out:take_umbrella?
|
97
97
|
,,
|
98
|
-
raining,
|
99
|
-
sunny,
|
100
|
-
cloudy,
|
101
|
-
cloudy,
|
102
|
-
cloudy,
|
98
|
+
raining, , yes
|
99
|
+
sunny, , no
|
100
|
+
cloudy, june, yes
|
101
|
+
cloudy, may, yes
|
102
|
+
cloudy, , no
|
103
103
|
"""
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
wi = {
|
108
|
-
"weather" => "raining",
|
109
|
-
"month" => "december"
|
110
|
-
}
|
111
|
-
do_test(CSV3, wi, {}, { "take_umbrella?" => "yes" }, false)
|
112
|
-
|
113
|
-
wi = {
|
114
|
-
"weather" => "cloudy",
|
115
|
-
"month" => "june"
|
116
|
-
}
|
117
|
-
do_test(CSV3, wi, {}, { "take_umbrella?" => "yes" }, false)
|
118
|
-
|
119
|
-
wi = {
|
120
|
-
"weather" => "cloudy",
|
121
|
-
"month" => "march"
|
122
|
-
}
|
123
|
-
do_test(CSV3, wi, {}, { "take_umbrella?" => "no" }, false)
|
124
|
-
end
|
105
|
+
def test_3
|
125
106
|
|
126
|
-
|
107
|
+
wi = {
|
108
|
+
"weather" => "raining",
|
109
|
+
"month" => "december"
|
110
|
+
}
|
111
|
+
do_test(CSV3, wi, {}, { "take_umbrella?" => "yes" }, false)
|
127
112
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
113
|
+
wi = {
|
114
|
+
"weather" => "cloudy",
|
115
|
+
"month" => "june"
|
116
|
+
}
|
117
|
+
do_test(CSV3, wi, {}, { "take_umbrella?" => "yes" }, false)
|
132
118
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
119
|
+
wi = {
|
120
|
+
"weather" => "cloudy",
|
121
|
+
"month" => "march"
|
122
|
+
}
|
123
|
+
do_test(CSV3, wi, {}, { "take_umbrella?" => "no" }, false)
|
124
|
+
end
|
137
125
|
|
138
|
-
|
139
|
-
h["weather"] = "cloudy"
|
140
|
-
h["month"] = "march"
|
141
|
-
do_test(CSV3, h, {}, { "take_umbrella?" => "no" }, false)
|
142
|
-
end
|
126
|
+
def test_3b
|
143
127
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
sports,europe,Alice
|
149
|
-
sports,,Bob
|
150
|
-
finance,america,Charly
|
151
|
-
finance,europe,Donald
|
152
|
-
finance,,Ernest
|
153
|
-
politics,asia,Fujio
|
154
|
-
politics,america,Gilbert
|
155
|
-
politics,,Henry
|
156
|
-
,,Zach
|
157
|
-
""")
|
158
|
-
|
159
|
-
h = {}
|
160
|
-
h["topic"] = "politics"
|
161
|
-
table.transform! h
|
162
|
-
|
163
|
-
assert_equal "Henry", h["team_member"]
|
164
|
-
end
|
128
|
+
h = {}
|
129
|
+
h["weather"] = "raining"
|
130
|
+
h["month"] = "december"
|
131
|
+
do_test(CSV3, h, {}, { "take_umbrella?" => "yes" }, false)
|
165
132
|
|
166
|
-
|
133
|
+
h = {}
|
134
|
+
h["weather"] = "cloudy"
|
135
|
+
h["month"] = "june"
|
136
|
+
do_test(CSV3, h, {}, { "take_umbrella?" => "yes" }, false)
|
167
137
|
|
168
|
-
|
138
|
+
h = {}
|
139
|
+
h["weather"] = "cloudy"
|
140
|
+
h["month"] = "march"
|
141
|
+
do_test(CSV3, h, {}, { "take_umbrella?" => "no" }, false)
|
142
|
+
end
|
169
143
|
|
170
|
-
|
144
|
+
def test_3c
|
171
145
|
|
172
|
-
|
173
|
-
|
174
|
-
|
146
|
+
table = Rufus::DecisionTable.new("""
|
147
|
+
in:topic,in:region,out:team_member
|
148
|
+
sports,europe,Alice
|
149
|
+
sports,,Bob
|
150
|
+
finance,america,Charly
|
151
|
+
finance,europe,Donald
|
152
|
+
finance,,Ernest
|
153
|
+
politics,asia,Fujio
|
154
|
+
politics,america,Gilbert
|
155
|
+
politics,,Henry
|
156
|
+
,,Zach
|
157
|
+
""")
|
175
158
|
|
176
|
-
|
159
|
+
h = {}
|
160
|
+
h["topic"] = "politics"
|
161
|
+
table.transform! h
|
177
162
|
|
178
|
-
|
179
|
-
|
180
|
-
h["month"] = "june"
|
163
|
+
assert_equal "Henry", h["team_member"]
|
164
|
+
end
|
181
165
|
|
182
|
-
|
166
|
+
CSV3D = "http://spreadsheets.google.com/pub?key=pCkopoeZwCNsMWOVeDjR1TQ&output=csv&gid=0"
|
183
167
|
|
184
|
-
|
168
|
+
def test_3d
|
185
169
|
|
186
|
-
|
187
|
-
h["weather"] = "cloudy"
|
188
|
-
h["month"] = "march"
|
170
|
+
#return unless online?
|
189
171
|
|
190
|
-
|
172
|
+
h = {}
|
173
|
+
h["weather"] = "raining"
|
174
|
+
h["month"] = "december"
|
191
175
|
|
192
|
-
|
193
|
-
end
|
176
|
+
do_test(CSV3D, h, {}, { "take_umbrella?" => "yes" }, false)
|
194
177
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
178
|
+
h = {}
|
179
|
+
h["weather"] = "cloudy"
|
180
|
+
h["month"] = "june"
|
181
|
+
|
182
|
+
sleep 0.5 # don't request the doc too often
|
183
|
+
|
184
|
+
do_test(CSV3D, h, {}, { "take_umbrella?" => "yes" }, false)
|
185
|
+
|
186
|
+
h = {}
|
187
|
+
h["weather"] = "cloudy"
|
188
|
+
h["month"] = "march"
|
189
|
+
|
190
|
+
sleep 0.5 # don't request the doc too often
|
191
|
+
|
192
|
+
do_test(CSV3D, h, {}, { "take_umbrella?" => "no" }, false)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_3e
|
196
|
+
|
197
|
+
table = Rufus::DecisionTable.new("""
|
198
|
+
in:topic,in:region,out:team_member
|
199
|
+
sports,europe,Alice
|
200
|
+
""")
|
201
|
+
|
202
|
+
h0 = {}
|
203
|
+
h0["topic"] = "politics"
|
204
|
+
h1 = table.transform! h0
|
205
|
+
|
206
|
+
assert_equal h0.object_id, h1.object_id
|
214
207
|
|
215
|
-
|
208
|
+
h0 = {}
|
209
|
+
h0["topic"] = "politics"
|
210
|
+
h1 = table.transform h0
|
211
|
+
|
212
|
+
assert_not_equal h0.object_id, h1.object_id
|
213
|
+
end
|
214
|
+
|
215
|
+
# CSV4 = \
|
216
216
|
#'''
|
217
217
|
#"in:weather", "in:month", "out:take_umbrella?"
|
218
218
|
#"","",""
|
@@ -223,58 +223,58 @@ cloudy, , no
|
|
223
223
|
#"cloudy","","no"
|
224
224
|
#'''
|
225
225
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
226
|
+
#def test_4
|
227
|
+
# h = {}
|
228
|
+
# h["weather"] = "raining"
|
229
|
+
# h["month"] = "december"
|
230
|
+
# do_test(CSV4, h, { "take_umbrella?" => "yes" }, false)
|
231
|
+
# h = {}
|
232
|
+
# h["weather"] = "cloudy"
|
233
|
+
# h["month"] = "june"
|
234
|
+
# do_test(CSV4, h, { "take_umbrella?" => "yes" }, false)
|
235
|
+
# h = {}
|
236
|
+
# h["weather"] = "cloudy"
|
237
|
+
# h["month"] = "march"
|
238
|
+
# do_test(CSV4, h, { "take_umbrella?" => "no" }, false)
|
239
|
+
#end
|
240
|
+
|
241
|
+
CSV5 = \
|
242
242
|
"""
|
243
243
|
through,ignorecase,,
|
244
244
|
,,,
|
245
245
|
in:fx, in:fy, out:fX, out:fY
|
246
246
|
,,,
|
247
|
-
a,
|
248
|
-
,
|
249
|
-
b,
|
250
|
-
,
|
247
|
+
a, , true,
|
248
|
+
, a, , true
|
249
|
+
b, , false,
|
250
|
+
, b, , false
|
251
251
|
"""
|
252
252
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
wi = {
|
262
|
-
"fx" => "a",
|
263
|
-
"fy" => "b"
|
264
|
-
}
|
265
|
-
do_test(CSV5, wi, {}, { "fX" => "true", "fY" => "false" }, false)
|
266
|
-
|
267
|
-
wi = {
|
268
|
-
"fx" => "A",
|
269
|
-
"fy" => "b"
|
270
|
-
}
|
271
|
-
do_test(CSV5, wi, {}, { "fX" => "true", "fY" => "false" }, false)
|
272
|
-
end
|
253
|
+
def test_5
|
254
|
+
|
255
|
+
wi = {
|
256
|
+
"fx" => "a",
|
257
|
+
"fy" => "a"
|
258
|
+
}
|
259
|
+
do_test(CSV5, wi, {}, { "fX" => "true", "fY" => "true" }, false)
|
273
260
|
|
274
|
-
|
275
|
-
|
261
|
+
wi = {
|
262
|
+
"fx" => "a",
|
263
|
+
"fy" => "b"
|
264
|
+
}
|
265
|
+
do_test(CSV5, wi, {}, { "fX" => "true", "fY" => "false" }, false)
|
276
266
|
|
277
|
-
|
267
|
+
wi = {
|
268
|
+
"fx" => "A",
|
269
|
+
"fy" => "b"
|
270
|
+
}
|
271
|
+
do_test(CSV5, wi, {}, { "fX" => "true", "fY" => "false" }, false)
|
272
|
+
end
|
273
|
+
|
274
|
+
#
|
275
|
+
# TEST 6
|
276
|
+
|
277
|
+
CSV6 = \
|
278
278
|
"""
|
279
279
|
,
|
280
280
|
in:fx, out:fy
|
@@ -284,23 +284,23 @@ in:fx, out:fy
|
|
284
284
|
,c
|
285
285
|
"""
|
286
286
|
|
287
|
-
|
287
|
+
def test_6
|
288
288
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
289
|
+
wi = {
|
290
|
+
"fx" => "5"
|
291
|
+
}
|
292
|
+
do_test(CSV6, wi, {}, { "fy" => "a" }, false)
|
293
293
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
294
|
+
wi = {
|
295
|
+
"fx" => "100.0001"
|
296
|
+
}
|
297
|
+
do_test(CSV6, wi, {}, { "fy" => "c" }, false)
|
298
|
+
end
|
299
299
|
|
300
|
-
|
301
|
-
|
300
|
+
#
|
301
|
+
# TEST 7
|
302
302
|
|
303
|
-
|
303
|
+
CSV7 = \
|
304
304
|
"""
|
305
305
|
,
|
306
306
|
in:fx, out:fy
|
@@ -310,25 +310,25 @@ in:fx, out:fy
|
|
310
310
|
,c
|
311
311
|
"""
|
312
312
|
|
313
|
-
|
313
|
+
def test_7
|
314
314
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
315
|
+
wi = {
|
316
|
+
"fx" => "5"
|
317
|
+
}
|
318
|
+
do_test(CSV7, wi, {}, { "fy" => "c" }, false)
|
319
319
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
320
|
+
wi = {
|
321
|
+
"fx" => "10"
|
322
|
+
}
|
323
|
+
do_test(CSV7, wi, {}, { "fy" => "b" }, false)
|
324
324
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
325
|
+
wi = {
|
326
|
+
"fx" => "10a"
|
327
|
+
}
|
328
|
+
do_test(CSV7, wi, {}, { "fy" => "a" }, false)
|
329
|
+
end
|
330
330
|
|
331
|
-
|
331
|
+
CSV8 = \
|
332
332
|
"""
|
333
333
|
in:efx,in:efy,out:efz
|
334
334
|
a,b,0
|
@@ -336,12 +336,12 @@ c,d,1
|
|
336
336
|
e,f,2
|
337
337
|
"""
|
338
338
|
|
339
|
-
|
339
|
+
def test_8
|
340
340
|
|
341
|
-
|
342
|
-
|
341
|
+
assert_equal CSV8.strip, Rufus::DecisionTable.new(CSV8).to_csv.strip
|
342
|
+
end
|
343
343
|
|
344
|
-
|
344
|
+
CSV9 = \
|
345
345
|
"""
|
346
346
|
in:fx,in:fy,out:fz
|
347
347
|
a,b,0
|
@@ -349,38 +349,38 @@ c,d,${r: 1 + 2}
|
|
349
349
|
e,f,2
|
350
350
|
"""
|
351
351
|
|
352
|
-
|
352
|
+
def test_9
|
353
353
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
354
|
+
wi = {
|
355
|
+
"fx" => "c",
|
356
|
+
"fy" => "d"
|
357
|
+
}
|
358
|
+
do_test(CSV9, wi, { :ruby_eval => true }, { "fz" => "3" }, false)
|
359
|
+
end
|
360
360
|
|
361
|
-
|
361
|
+
CSV10 = \
|
362
362
|
"""
|
363
363
|
in:fx,in:fx,out:fz
|
364
364
|
>90,<92,ok
|
365
365
|
,,bad
|
366
366
|
"""
|
367
367
|
|
368
|
-
|
368
|
+
def test_10
|
369
369
|
|
370
|
-
|
371
|
-
|
370
|
+
wi = { "fx" => "91" }
|
371
|
+
do_test(CSV10, wi, {}, { "fz" => "ok" }, false)
|
372
372
|
|
373
|
-
|
374
|
-
|
373
|
+
wi = { "fx" => "95" }
|
374
|
+
do_test(CSV10, wi, {}, { "fz" => "bad" }, false)
|
375
375
|
|
376
|
-
|
377
|
-
|
378
|
-
|
376
|
+
wi = { "fx" => "81" }
|
377
|
+
do_test(CSV10, wi, {}, { "fz" => "bad" }, false)
|
378
|
+
end
|
379
379
|
|
380
|
-
|
381
|
-
|
380
|
+
#
|
381
|
+
# Fu Zhang's test case
|
382
382
|
|
383
|
-
|
383
|
+
CSV11 = \
|
384
384
|
'''
|
385
385
|
through
|
386
386
|
in:f1,in:f1,in:f2,in:f3,out:o1,out:e1,out:e2
|
@@ -392,88 +392,88 @@ in:f1,in:f1,in:f2,in:f3,out:o1,out:e1,out:e2
|
|
392
392
|
<100,>=95,,>2.0,"Invalid",,
|
393
393
|
'''
|
394
394
|
|
395
|
-
|
395
|
+
def test_11
|
396
396
|
|
397
|
-
|
398
|
-
|
399
|
-
|
397
|
+
wi = { "f1" => 97, "f2" => 5 }
|
398
|
+
do_test CSV11, wi, {}, { "o1" => "Expection1" }, false
|
399
|
+
end
|
400
400
|
|
401
|
-
|
402
|
-
|
401
|
+
#
|
402
|
+
# 'accumulate'
|
403
403
|
|
404
|
-
|
404
|
+
CSV12 = \
|
405
405
|
"""
|
406
406
|
accumulate
|
407
407
|
,,,
|
408
408
|
in:fx, in:fy, out:fX, out:fY
|
409
409
|
,,,
|
410
|
-
a,
|
411
|
-
,
|
412
|
-
b,
|
413
|
-
,
|
410
|
+
a, , red, green
|
411
|
+
, a, blue, purple
|
412
|
+
b, , yellow, beige
|
413
|
+
, b, white, kuro
|
414
414
|
"""
|
415
415
|
|
416
|
-
|
416
|
+
def test_12
|
417
417
|
|
418
|
-
|
419
|
-
|
418
|
+
wi = { "fx" => "a", "fy" => "a" }
|
419
|
+
do_test CSV12, wi, {}, { "fX" => "red;blue", "fY" => "green;purple" }, false
|
420
420
|
|
421
|
-
|
422
|
-
|
423
|
-
|
421
|
+
wi = { "fx" => "a", "fy" => "a", "fX" => "BLACK" }
|
422
|
+
do_test CSV12, wi, {}, {
|
423
|
+
"fX" => "BLACK;red;blue", "fY" => "green;purple" }, false
|
424
424
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
425
|
+
wi = { "fx" => "a", "fy" => "a", "fX" => [ "BLACK", "BLUE" ] }
|
426
|
+
do_test CSV12, wi, {}, {
|
427
|
+
"fX" => "BLACK;BLUE;red;blue", "fY" => "green;purple" }, false
|
428
|
+
end
|
429
429
|
|
430
|
-
|
431
|
-
|
432
|
-
dt = Rufus::DecisionTable.new ",\n,"
|
433
|
-
class << dt
|
434
|
-
public :to_ruby_range
|
435
|
-
end
|
436
|
-
|
437
|
-
assert_not_nil dt.to_ruby_range("99..100")
|
438
|
-
assert_not_nil dt.to_ruby_range("99...100")
|
439
|
-
assert_not_nil dt.to_ruby_range("99.12..100.56")
|
440
|
-
assert_nil dt.to_ruby_range("99....100")
|
441
|
-
assert_nil dt.to_ruby_range("9a9..100")
|
442
|
-
assert_nil dt.to_ruby_range("9a9..1a00")
|
443
|
-
|
444
|
-
assert_equal dt.to_ruby_range("a..z"), 'a'..'z'
|
445
|
-
assert_equal dt.to_ruby_range("a..Z"), 'a'..'Z'
|
446
|
-
assert_equal dt.to_ruby_range("a...z"), 'a'...'z'
|
447
|
-
assert_nil dt.to_ruby_range("a..%")
|
448
|
-
|
449
|
-
r = dt.to_ruby_range "4..6"
|
450
|
-
assert r.include?(5)
|
451
|
-
assert r.include?("5")
|
452
|
-
assert (not r.include?(7))
|
453
|
-
assert (not r.include?("7"))
|
454
|
-
end
|
430
|
+
def test_to_ruby_range
|
455
431
|
|
456
|
-
|
457
|
-
|
432
|
+
dt = Rufus::DecisionTable.new ",\n,"
|
433
|
+
class << dt
|
434
|
+
public :to_ruby_range
|
435
|
+
end
|
458
436
|
|
459
|
-
|
437
|
+
assert_not_nil dt.to_ruby_range("99..100")
|
438
|
+
assert_not_nil dt.to_ruby_range("99...100")
|
439
|
+
assert_not_nil dt.to_ruby_range("99.12..100.56")
|
440
|
+
assert_nil dt.to_ruby_range("99....100")
|
441
|
+
assert_nil dt.to_ruby_range("9a9..100")
|
442
|
+
assert_nil dt.to_ruby_range("9a9..1a00")
|
443
|
+
|
444
|
+
assert_equal dt.to_ruby_range("a..z"), 'a'..'z'
|
445
|
+
assert_equal dt.to_ruby_range("a..Z"), 'a'..'Z'
|
446
|
+
assert_equal dt.to_ruby_range("a...z"), 'a'...'z'
|
447
|
+
assert_nil dt.to_ruby_range("a..%")
|
448
|
+
|
449
|
+
r = dt.to_ruby_range "4..6"
|
450
|
+
assert r.include?(5)
|
451
|
+
assert r.include?("5")
|
452
|
+
assert (not r.include?(7))
|
453
|
+
assert (not r.include?("7"))
|
454
|
+
end
|
455
|
+
|
456
|
+
#
|
457
|
+
# Testing ranges
|
458
|
+
|
459
|
+
CSV13 = \
|
460
460
|
"""
|
461
461
|
in:fx,out:fz
|
462
462
|
90..92,ok
|
463
463
|
,bad
|
464
464
|
"""
|
465
465
|
|
466
|
-
|
466
|
+
def test_13
|
467
467
|
|
468
|
-
|
469
|
-
|
468
|
+
wi = { "fx" => "91" }
|
469
|
+
do_test CSV13, wi, {}, { "fz" => "ok" }, false
|
470
470
|
|
471
|
-
|
472
|
-
|
471
|
+
wi = { "fx" => "95" }
|
472
|
+
do_test CSV13, wi, {}, { "fz" => "bad" }, false
|
473
473
|
|
474
|
-
|
475
|
-
|
476
|
-
|
474
|
+
wi = { "fx" => "81" }
|
475
|
+
do_test CSV13, wi, {}, { "fz" => "bad" }, false
|
476
|
+
end
|
477
477
|
|
478
478
|
end
|
479
479
|
|