Author: particle
Date: Thu Jan 12 18:26:20 2006
New Revision: 11144
Modified:
trunk/t/pmc/resizablestringarray.t
Log:
PMC: add tests for ResizableStringArray PMC
~ shift/unshift
~ stress tests
~ sparse access
Modified: trunk/t/pmc/resizablestringarray.t
==============================================================================
--- trunk/t/pmc/resizablestringarray.t (original)
+++ trunk/t/pmc/resizablestringarray.t Thu Jan 12 18:26:20 2006
@@ -6,7 +6,7 @@ use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 16;
+use Parrot::Test tests => 27;
=head1 NAME
@@ -318,6 +318,18 @@ CODE
two zero one zero
OUTPUT
+output_is(<<'CODE', <<'OUTPUT', "creation");
+ new P0, .ResizableStringArray
+ set I0, P0
+ print "Created ResizableStringArray with "
+ print I0
+ print " elements to start with.\n"
+ end
+CODE
+Created ResizableStringArray with 0 elements to start with.
+OUTPUT
+
+
output_is(<<'CODE', <<'OUTPUT', 'basic pop');
new P0, .ResizableStringArray
set P0[0], "foo"
@@ -392,6 +404,577 @@ output_like(<<'CODE', <<'OUTPUT', 'pop f
CODE
/ResizableStringArray: Can't pop from an empty array!/
OUTPUT
+#'
+
+pir_output_is(<< 'CODE', << 'OUTPUT', "push and pop");
+.sub test :main
+ .local string s, s_elem
+ .local pmc pmc_arr
+ .local int elements
+
+ s = 'a'
+ pmc_arr = new ResizableStringArray
+
+ print_num_elements( pmc_arr )
+
+ push pmc_arr, s
+ print s
+ print_num_elements( pmc_arr )
+
+ push pmc_arr, 'b'
+ print 'b'
+ print_num_elements( pmc_arr )
+
+ print_num_elements( pmc_arr )
+
+ s_elem= pop pmc_arr
+ print s_elem
+ print_num_elements( pmc_arr )
+
+ s_elem= pop pmc_arr
+ print s_elem
+ print_num_elements( pmc_arr )
+
+ pmc_arr = 63
+ push pmc_arr, 'd'
+ push pmc_arr, 'e'
+ push pmc_arr, 'f'
+ push pmc_arr, 'g'
+ s_elem = pop pmc_arr
+ s_elem = pop pmc_arr
+ s_elem = pop pmc_arr
+ print s_elem
+ print_num_elements(pmc_arr)
+.end
+
+.sub print_num_elements
+ .param pmc pmc_arr
+ .local int elements
+ elements= pmc_arr
+ print '['
+ print elements
+ print "]\n"
+ .return()
+.end
+
+CODE
+[0]
+a[1]
+b[2]
+[2]
+b[1]
+a[0]
+e[64]
+OUTPUT
+
+
+pir_output_like(<< 'CODE', << 'OUTPUT', "pop bounds checking");
+.sub 'test' :main
+ P0 = new .ResizableStringArray
+ pop S0, P0
+.end
+CODE
+/ResizableStringArray: Can't pop from an empty array!.*/
+OUTPUT
+#'
+
+
+pir_output_is(<< 'CODE', << 'OUTPUT', "unshift and shift");
+.sub test :main
+ .local string s, s_elem
+ .local pmc pmc_arr
+ .local int elements
+
+ s= 'a'
+ pmc_arr= new ResizableStringArray
+
+ print_num_elements( pmc_arr )
+
+ unshift pmc_arr, s
+ print s
+ print_num_elements( pmc_arr )
+
+ unshift pmc_arr, 'b'
+ print 'b'
+ print_num_elements( pmc_arr )
+
+ print_num_elements( pmc_arr )
+
+ s_elem= shift pmc_arr
+ print s_elem
+ print_num_elements( pmc_arr )
+
+ s_elem= shift pmc_arr
+ print s_elem
+ print_num_elements( pmc_arr )
+
+ pmc_arr = 62
+ unshift pmc_arr, 'c'
+ unshift pmc_arr, 'd'
+ unshift pmc_arr, 'e'
+ unshift pmc_arr, 'f'
+ s_elem = shift pmc_arr
+ s_elem = shift pmc_arr
+ s_elem = shift pmc_arr
+ print s_elem
+ print_num_elements(pmc_arr)
+
+ # Set same size array is currently
+ pmc_arr = 63
+ print_num_elements(pmc_arr)
+.end
+
+.sub print_num_elements
+ .param pmc pmc_arr
+ .local int elements
+ elements= pmc_arr
+ print '['
+ print elements
+ print "]\n"
+ .return()
+.end
+
+CODE
+[0]
+a[1]
+b[2]
+[2]
+b[1]
+a[0]
+d[63]
+[63]
+OUTPUT
+
+
+pir_output_like(<< 'CODE', << 'OUTPUT', "shift bounds checking");
+.sub 'test' :main
+ P0 = new .ResizableStringArray
+ shift S0, P0
+.end
+CODE
+/ResizableStringArray: Can't shift from an empty array!.*/
+OUTPUT
+#'
+
+
+output_is(<<'CODE', <<'OUTPUT', "aerobics", todo => 'not yet working');
+ new P0, .ResizableStringArray
+ set I10, 10000
+
+ set I1, 0
+ set I0, 0
+buildup:
+ ge I0, I10, postBuildUp
+
+ mod I4, I1, 2
+ set S4, I4
+ push P0, S4
+ add I1, 1 # Push P0, mod I1++, 2
+ mod I4, I1, 2
+ set S4, I4
+ push P0, S4
+ add I1, 1 # Push P0, mod I1++, 2
+ mod I4, I1, 2
+ set S4, I4
+ push P0, S4
+ add I1, 1 # Push P0, mod I1++, 2
+
+ pop S2, P0
+ set I2, S2
+ mul I3, I0, 3
+ add I3, 2
+ mod I3, 2
+ ne I2, I3, errFirstPop # fail if pop != mod I0 * 3 + 2, 2
+
+ pop S2, P0
+ set I2, S2
+ mul I3, I0, 3
+ add I3, 1
+ mod I3, 2
+ ne I2, I3, errSecondPop # fail if pop != mod I0 * 3 + 1, 2
+
+ set I2, P0
+ add I3, I0, 1
+ ne I2, I3, errBuildLen # fail if length != I0 + 1
+
+ add I0, 1
+ branch buildup
+postBuildUp:
+
+ set I0, 0
+checkBuildUpLeft:
+ ge I0, I10, postCheckBuildUpLeft
+ set S2, P0[I0]
+ set I2, S2
+ mul I3, I0, 3
+ mod I3, 2
+ ne I2, I3, errLeftGet
+ add I0, 1
+ branch checkBuildUpLeft
+postCheckBuildUpLeft:
+
+ mul I0, I10, -1
+checkBuildUpRight:
+ ge I0, 0, postCheckBuildUpRight
+ set S2, P0[I0]
+ set I2, S2
+ add I3, I0, I10
+ mul I3, 3
+ mod I3, 2
+ ne I2, I3, errRightGet
+ add I0, 1
+ branch checkBuildUpRight
+postCheckBuildUpRight:
+
+ set I0, I10
+tearDown:
+ le I0, 0, postTearDown
+ pop S2, P0
+ set I2, S2
+ sub I3, I0, 1
+ mod I3, 2
+ ne I2, I3, errTearDown
+
+ sub I0, 1
+ branch tearDown
+postTearDown:
+
+ print "I need a shower.\n"
+ end
+errFirstPop:
+ print "FAILED: first pop\n"
+ bsr info
+ end
+errSecondPop:
+ print "FAILED: second pop\n"
+ bsr info
+ end
+errBuildLen:
+ print "FAILED: buildup length\n"
+ bsr info
+ end
+errLeftGet:
+ print "FAILED: left get\n"
+ bsr info
+ end
+errRightGet:
+ print "FAILED: right get\n"
+ bsr info
+ end
+errTearDown:
+ print "FAILED: tear down cap\n"
+ bsr info
+ end
+info:
+ print "Found: "
+ print I2
+ print "\nWanted: "
+ print I3
+ print "\n"
+ ret
+CODE
+I need a shower.
+OUTPUT
+
+
+my $SPEEDUP = $ENV{RUNNING_MAKE_TEST} ? "gc_debug 0\n" : "";
+output_is($SPEEDUP . <<'CODE', <<'OUTPUT', "direct access");
+ new P0, .ResizableStringArray
+ set S0, ""
+ set S1, "abcdefghijklmnopqrst"
+ set I10, 100000
+ set I0, 0
+lp:
+ mod I2, I0, 2
+ set S30, I2
+ set P0[I0], S30
+ inc I0
+ mod I9, I0, 100
+ ne I9, 0, lp1
+ # force GC => 142 DOD + 142 collects / 10^5 accesses
+ new P1, .PerlArray
+ set P1[I0], I0
+ concat S0, S1, S1
+ set S2, S0
+ set S0, S1
+ set S2, ""
+lp1:
+ le I0, I10, lp
+
+ set I0, 0
+lp2:
+ mod I2, I0, 2
+ set S29, P0[I0]
+ set I16, S29
+ ne I2, I16, err
+ inc I0
+ le I0, I10, lp2
+ print "ok\n"
+ end
+err:
+ print "err: wanted "
+ print I0
+ print " got "
+ print S29
+ print "\n"
+ end
+CODE
+ok
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "direct access 2");
+ #new P0, .IntList
+ new P0, .ResizableStringArray
+ set I10, 1100000
+ set I0, 1
+lp1:
+ add I1, I0, 5
+ mod I2, I1, 2
+ set S2, I2
+ set P0[I0], S2
+ add I3, I1, I0
+ mod I2, I3, 2
+ set S2, I2
+ push P0, S2
+ shl I0, I0, 1
+ inc I0
+ le I0, I10, lp1
+
+ set I0, 1
+lp2:
+ add I1, I0, 5
+ mod I5, I1, 2
+ # check at I0
+ set S2, P0[I0]
+ set I2, S2
+ ne I2, I5, err
+ add I4, I0, 1
+ # and pushed value at I0+1
+ set S4, P0[I4]
+ set I4, S4
+ add I3, I1, I0
+ mod I5, I3, 2
+ ne I5, I4, err
+
+ shl I0, I0, 1
+ inc I0
+ le I0, I10, lp2
+ print "ok\n"
+ end
+err:
+ print "not ok "
+ print I0
+ print " "
+ print I1
+ print " "
+ print I2
+ print " "
+ print I3
+ print " "
+ print I4
+ print " "
+ print I5
+ print " "
+ print I6
+ print " "
+ print I7
+ print "\n"
+
+ end
+CODE
+ok
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "sparse access");
+ new P0, .ResizableStringArray
+ set I10, 110000
+ set I0, 1
+lp1:
+ add I1, I0, 5
+ mod I9, I1, 2
+ set S9, I9
+ set P0[I0], S9
+ add I3, I1, I0
+ mod I9, I3, 2
+ set S9, I9
+ push P0, S9
+ shl I0, I0, 1
+ inc I0
+ le I0, I10, lp1
+
+ set I0, 1
+lp2:
+ add I1, I0, 5
+ mod I9, I1, 2
+ # check at I0
+ set S2, P0[I0]
+ set I2, S2
+ ne I2, I9, err
+ add I4, I0, 1
+ # and pushed value at I0+1
+ set S4, P0[I4]
+ set I4, S4
+ add I3, I1, I0
+ mod I9, I3, 2
+ ne I9, I4, err
+
+ shl I0, I0, 1
+ inc I0
+ le I0, I10, lp2
+ print "ok 1\n"
+
+ # now repeat and fill some holes
+
+ set I0, 777
+lp3:
+ add I1, I0, 5
+ mod I9, I1, 2
+ set S9, I9
+ set P0[I0], S9
+ add I0, I0, 666
+ le I0, I10, lp3
+
+ set I0, 777
+lp4:
+ add I1, I0, 5
+ mod I9, I1, 2
+ # check at I0
+ set S2, P0[I0]
+ set I2, S2
+ ne I2, I9, err
+
+ add I0, I0, 666
+ le I0, I10, lp4
+ print "ok 2\n"
+ end
+err:
+ print "not ok "
+ print I0
+ print " "
+ print I1
+ print " "
+ print I2
+ print " "
+ print I3
+ print " "
+ print I4
+ print "\n"
+
+ end
+CODE
+ok 1
+ok 2
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "check for zeroedness");
+ new P0, .ResizableStringArray
+ set I0, 0
+lp1:
+ set S0, '0'
+ push P0, S0
+ inc I0
+ lt I0, 100, lp1
+
+ set I2, 10000
+ #set I0, 100
+ set P0, I2
+lp2:
+ set S1, P0[I0]
+ set I1, S1
+ ne I1, 0, err
+ inc I0
+ lt I0, I2, lp2
+ print "ok\n"
+ end
+err:
+ print "Found non-zero value "
+ print I1
+ print " at "
+ print I0
+ print "\n"
+ end
+CODE
+ok
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "pop into sparse");
+ new P0, .ResizableStringArray
+ set I10, 100
+ set I0, 0
+ # push some values at start
+lp1:
+ mod I5, I0, 2
+ set S5, I5
+ push P0, S5
+ inc I0
+ lt I0, I10, lp1
+
+ # create sparse
+ set I0, 100000
+ set I1, 1000
+ mod I5, I1, 2
+ #set P0[I0], I1
+ set S5, I5
+ set P0[I0], S5
+ inc I1
+lp2:
+ # push some values after hole
+ mod I5, I1, 2
+ set S5, I5
+ push P0, S5
+ inc I1
+ le I1, 1100, lp2
+ dec I1
+
+ set I3, P0
+lp3:
+ set I4, P0
+ ne I3, I4, err1
+ pop S2, P0
+ set I2, S2
+ dec I3
+ mod I5, I1, 2
+ ne I2, I5, err2
+ gt I3, I0, cont1
+ lt I3, I10, cont1
+ set I1, 0
+
+ gt I3, I10, lp3
+ set I1, I10
+
+cont1:
+ dec I1
+ eq I1, 0, ok
+ branch lp3
+ok:
+ print "ok\n"
+ end
+err1: set S0, "len"
+ branch err
+err2:
+ set S0, "val"
+err:
+ print "nok "
+ print S0
+ print " "
+ print I0
+ print " "
+ print I1
+ print " "
+ print I2
+ print " "
+ print I3
+ print " "
+ print I4
+ print " "
+ print I5
+ end
+CODE
+ok
+OUTPUT
output_is(<< 'CODE', << 'OUTPUT', "clone");
new P0, .ResizableStringArray