2 # Copyright (C) 2001-2005, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 20;
13 t/pmc/resizablebooleanarray.t - testing the ResizableBooleanArray PMC
17 % prove t/pmc/resizablebooleanarray.t
21 Tests C<ResizableBooleanArray> PMC. Checks size, sets various elements, including
22 out-of-bounds test. Checks INT and PMC keys.
26 my $fp_equality_macro = <<'ENDOFMACRO';
27 .macro fp_eq ( J, K, L )
36 gt N2, 0.000001, .$FPEQNOK
56 lt N2, 0.000001, .$FPNENOK
69 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting array size" );
70 new P0, .ResizableBooleanArray
109 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting first element" );
110 new P0, .ResizableBooleanArray
138 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting second element" );
139 new P0, .ResizableBooleanArray
167 # TODO: Rewrite these properly when we have exceptions
169 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting out-of-bounds elements" );
170 new P0, .ResizableBooleanArray
197 pasm_output_is( <<'CODE', <<'OUTPUT', "Getting out-of-bounds elements" );
198 new P0, .ResizableBooleanArray
208 pasm_output_is( <<"CODE", <<'OUTPUT', "Set via PMC keys, access via INTs" );
209 @{[ $fp_equality_macro ]}
210 new P0, .ResizableBooleanArray
244 pasm_output_is( <<"CODE", <<'OUTPUT', "Set via INTs, access via PMC Keys" );
245 @{[ $fp_equality_macro ]}
246 new P0, .ResizableBooleanArray
290 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" );
293 pmc1 = new ResizableBooleanArray
295 does bool1, pmc1, "scalar"
298 does bool1, pmc1, "array"
301 does bool1, pmc1, "no_interface"
312 pir_output_is( << 'CODE', << 'OUTPUT', "push integer" );
315 pmc1 = new ResizableBooleanArray
333 pasm_output_is( <<'CODE', <<'OUTPUT', "creation" );
334 new P0, .ResizableBooleanArray
336 print "Created ResizableBooleanArray with "
338 print " elements to start with.\n"
341 Created ResizableBooleanArray with 0 elements to start with.
344 pir_output_is( << 'CODE', << 'OUTPUT', "push and pop" );
351 pmc_arr = new ResizableBooleanArray
353 print_num_elements( pmc_arr )
357 print_num_elements( pmc_arr )
361 print_num_elements( pmc_arr )
363 print_num_elements( pmc_arr )
367 print_num_elements( pmc_arr )
371 print_num_elements( pmc_arr )
382 print_num_elements(pmc_arr)
385 .sub print_num_elements
405 pir_output_like( << 'CODE', << 'OUTPUT', "pop bounds checking" );
407 P0 = new .ResizableBooleanArray
411 /ResizableBooleanArray: Can't pop from an empty array!.*/
416 pir_output_is( << 'CODE', << 'OUTPUT', "unshift and shift" );
423 pmc_arr = new ResizableBooleanArray
425 # No elements are set
426 print_num_elements( pmc_arr )
428 # Set two of the first three elements
431 print_num_elements( pmc_arr )
433 # Unshift a "1" element on
436 print_num_elements( pmc_arr )
438 # Unshift a "0" element on
441 print_num_elements( pmc_arr )
443 # Shift an element off
444 i_elem= shift pmc_arr
446 print_num_elements( pmc_arr )
448 # Shift an element off
449 i_elem= shift pmc_arr
451 print_num_elements( pmc_arr )
455 print_num_elements(pmc_arr)
457 # Unshift 4 elements on
462 print_num_elements(pmc_arr)
464 # Shift 3 elements off
465 i_elem = shift pmc_arr
466 i_elem = shift pmc_arr
467 i_elem = shift pmc_arr
469 print_num_elements(pmc_arr)
471 # Set same size array is currently
473 print_num_elements(pmc_arr)
477 print_num_elements(pmc_arr)
479 # Shift off 99 elements
483 i_elem = shift pmc_arr
485 if counter > 0 goto shift_loop
488 print_num_elements(pmc_arr)
491 .sub print_num_elements
537 pir_output_like( << 'CODE', << 'OUTPUT', "shift bounds checking" );
539 P0 = new .ResizableBooleanArray
543 /ResizableBooleanArray: Can't shift from an empty array!.*/
548 pasm_output_is( <<'CODE', <<'OUTPUT', "aerobics" );
549 new P0, .ResizableBooleanArray
555 ge I0, I10, postBuildUp
559 add I1, 1 # Push P0, mod I1++, 2
562 add I1, 1 # Push P0, mod I1++, 2
565 add I1, 1 # Push P0, mod I1++, 2
571 ne I2, I3, errFirstPop # fail if pop != mod I0 * 3 + 2, 2
577 ne I2, I3, errSecondPop # fail if pop != mod I0 * 3 + 1, 2
581 ne I2, I3, errBuildLen # fail if length != I0 + 1
589 ge I0, I10, postCheckBuildUpLeft
593 ne I2, I3, errLeftGet
595 branch checkBuildUpLeft
596 postCheckBuildUpLeft:
600 ge I0, 0, postCheckBuildUpRight
605 ne I2, I3, errRightGet
607 branch checkBuildUpRight
608 postCheckBuildUpRight:
612 le I0, 0, postTearDown
616 ne I2, I3, errTearDown
622 print "I need a shower.\n"
625 print "FAILED: first pop\n"
629 print "FAILED: second pop\n"
633 print "FAILED: buildup length\n"
637 print "FAILED: left get\n"
641 print "FAILED: right get\n"
645 print "FAILED: tear down cap\n"
659 pasm_output_is( <<'CODE', <<'OUTPUT', "direct access 2" );
661 new P0, .ResizableBooleanArray
683 # and pushed value at I0+1
718 pasm_output_is( <<'CODE', <<'OUTPUT', "sparse access" );
719 new P0, .ResizableBooleanArray
741 # and pushed value at I0+1
752 # now repeat and fill some holes
794 pasm_output_is( <<'CODE', <<'OUTPUT', "check for zeroedness" );
795 new P0, .ResizableBooleanArray
813 print "Found non-zero value "
823 pasm_output_is( <<'CODE', <<'OUTPUT', "pop into sparse" );
824 new P0, .ResizableBooleanArray
827 # push some values at start
842 # push some values after hole
896 local $TODO = "this is broken";
898 pasm_output_is( <<'CODE', <<'OUTPUT', "clone" );
899 new P0, .ResizableBooleanArray
939 # cperl-indent-level: 4
942 # vim: expandtab shiftwidth=4: