2 # Copyright (C) 2007-2008, Parrot Foundation.
11 % prove t/library/range.t
15 Tests the Range class.
20 .include 'test_more.pir'
21 load_bytecode 'Range.pbc'
25 # XXX Convert this to the PDD15 way of creating an object
26 # at the same time you specify the attributes...
45 .local string test_desc
46 test_desc = "1..3, shift until exhausted"
51 setattribute $P0, 'from', $P1
54 setattribute $P0, 'to', $P1
70 # XXX should have more thorough exception check
79 .local string test_desc
80 test_desc = "-1..3:by(2), shift until exhausted"
84 setattribute $P0, 'from', $P1
87 setattribute $P0, 'to', $P1
90 setattribute $P0, 'by', $P1
94 is($I0, -1, '2 - 1st')
102 ok(0,'2 - exhausted')
107 # XXX should have more thorough exception check
108 ok(1,'2 - exhausted')
115 .local string test_desc
116 test_desc = "-1..4:by(2), shift until exhausted"
120 setattribute $P0, 'from', $P1
123 setattribute $P0, 'to', $P1
126 setattribute $P0, 'by', $P1
130 is($I0, -1, '3 - 1st')
132 is($I0, 1, '3 - 2nd')
134 is($I0, 3, '3 - 3rd')
138 ok(0,'3 - exhausted')
143 # XXX should have more thorough exception check
144 ok(1,'3 - exhausted')
151 .local string test_desc
152 test_desc = "1..3, pop until exhausted"
157 setattribute $P0, 'from', $P1
160 setattribute $P0, 'to', $P1
163 is($I0, 3, '4 - 1st')
165 is($I0, 2, '4 - 2nd')
167 is($I0, 1, '4 - 3rd')
171 ok(0,'4 - exhausted')
176 # XXX should have more thorough exception check
177 ok(1,'4 - exhausted')
184 .local string test_desc
185 test_desc = "-1..3:by(2), pop until exhausted"
189 setattribute $P0, 'from', $P1
192 setattribute $P0, 'to', $P1
195 setattribute $P0, 'by', $P1
199 is($I0, 3, '5 - 1st')
201 is($I0, 1, '5 - 2nd')
203 is($I0, -1, '5 - 3rd')
207 ok(0,'5 - exhausted')
212 # XXX should have more thorough exception check
213 ok(1,'5 - exhausted')
220 .local string test_desc
221 test_desc = "-1..4:by(2), pop until exhausted"
225 setattribute $P0, 'from', $P1
228 setattribute $P0, 'to', $P1
231 setattribute $P0, 'by', $P1
235 is($I0, 4, '6 - 1st')
237 is($I0, 2, '6 - 2nd')
239 is($I0, 0, '6 - 3rd')
243 ok(0,'6 - exhausted')
248 # XXX should have more thorough exception check
249 ok(1,'6 - exhausted')
256 .local string test_desc
257 test_desc = "1..42.5, shift & pop"
261 setattribute $P0, 'from', $P1
264 setattribute $P0, 'to', $P1
268 is($N0, 1, '7 - 1st')
270 is($N0, 42.5, '7 - last')
272 $N0 = $P0.'get_from'()
273 is($N0, 2, '7 - from')
276 is($N0, 41.5, '7 - to')
283 .local string test_desc
284 test_desc = "1..3, reverse, shift until exhausted"
289 setattribute $P0, 'from', $P1
292 setattribute $P0, 'to', $P1
296 ok(1, '8 - reversed')
299 is($I0, 3, '8 - 1st')
301 is($I0, 2, '8 - 2nd')
303 is($I0, 1, '8 - 3rd')
307 ok(0,'8 - exhausted')
312 # XXX should have more thorough exception check
313 ok(1,'8 - exhausted')
320 .local string test_desc
321 test_desc = "1..3, reverse, pop until exhausted"
326 setattribute $P0, 'from', $P1
329 setattribute $P0, 'to', $P1
333 ok(1, '9 - reversed')
336 is($I0, 1, '9 - 1st')
338 is($I0, 2, '9 - 2nd')
340 is($I0, 3, '9 - 3rd')
344 ok(0,'9 - exhausted')
349 # XXX should have more thorough exception check
350 ok(1,'9 - exhausted')
357 .local string test_desc
358 test_desc = "1..3, get attributes..."
363 setattribute $P0, 'from', $P1
366 setattribute $P0, 'to', $P1
369 $I0 = $P0.'get_from'()
370 is($I0, 1, '10 - from')
372 is($I0, 3, '10 - to')
373 $I0 = $P0.'get_min'()
374 is($I0, 1, '10 - min')
375 $I0 = $P0.'get_max'()
376 is($I0, 3, '10 - max')
377 $P0 = $P0.'get_minmax'()
379 is($I0, 1, '10 - min of minmax')
381 is($I0, 3, '10 - max of minmax')
388 .local string test_desc
389 test_desc = "3..1:by(-1), get attributes"
394 setattribute $P0, 'from', $P1
397 setattribute $P0, 'to', $P1
400 setattribute $P0, 'by', $P1
403 $I0 = $P0.'get_from'()
404 is($I0, 3, '11 - from')
406 is($I0, 1, '11 - to')
407 $I0 = $P0.'get_min'()
408 is($I0, 1, '11 - min')
409 $I0 = $P0.'get_max'()
410 is($I0, 3, '11 - max')
411 $P0 = $P0.'get_minmax'()
413 is($I0, 1, '11 - min of minmax')
415 is($I0, 3, '11 - max of minmax')
422 .local string test_desc
423 test_desc = "1..3, reverse, get attributes"
428 setattribute $P0, 'from', $P1
431 setattribute $P0, 'to', $P1
435 $I0 = $P0.'get_from'()
436 is($I0, 3, '11 - from')
438 is($I0, 1, '11 - to')
439 $I0 = $P0.'get_min'()
440 is($I0, 1, '11 - min')
441 $I0 = $P0.'get_max'()
442 is($I0, 3, '11 - max')
443 $P0 = $P0.'get_minmax'()
445 is($I0, 1, '11 - min of minmax')
447 is($I0, 3, '11 - max of minmax')
454 .local string test_desc
455 test_desc = "1..4, vtable shift, all varieties"
460 setattribute $P0, 'from', $P1
463 setattribute $P0, 'to', $P1
467 is($P1, 1, '13 - 1st')
469 is($I0, 2, '13 - 2nd')
471 is($N0, 3.0, '13 - 3rd')
473 is($S0, "4", '13 - 4th')
480 .local string test_desc
481 test_desc = "1..4, vtable pop, all varieties"
486 setattribute $P0, 'from', $P1
489 setattribute $P0, 'to', $P1
493 is($P1, 4, '14 - 1st')
495 is($I0, 3, '14 - 2nd')
497 is($N0, 2.0, '14 - 3rd')
499 is($S0, "1", '14 - 4th')
509 # vim: expandtab shiftwidth=4 ft=pir: