cvsuser     05/01/03 10:44:12

  Modified:    classes  resizableintegerarray.pmc
               t/pmc    resizableintegerarray.t
  Log:
   Implement and test pop_integer
  
  Revision  Changes    Path
  1.5       +32 -3     parrot/classes/resizableintegerarray.pmc
  
  Index: resizableintegerarray.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/resizableintegerarray.pmc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- resizableintegerarray.pmc 12 Dec 2004 23:03:45 -0000      1.4
  +++ resizableintegerarray.pmc 3 Jan 2005 18:44:11 -0000       1.5
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: resizableintegerarray.pmc,v 1.4 2004/12/12 23:03:45 chromatic Exp $
  +$Id: resizableintegerarray.pmc,v 1.5 2005/01/03 18:44:11 scog Exp $
   
   =head1 NAME
   
  @@ -107,9 +107,9 @@
   
   /*
   
  -=item C<void push_integer (STRING* value)>
  +=item C<void push_integer (INTVAL value)>
   
  -Extends the array by adding an element of value C<*value> to the end of
  +Extends the array by adding an element of value C<value> to the end of
   the array.
   
   =cut
  @@ -123,6 +123,35 @@
   
   /*
   
  +=item C<INTVAL pop_integer()>
  +
  +Removes and returns the last element in the array.
  +
  +=cut
  +
  +*/
  +
  +    INTVAL pop_integer() {
  +        INTVAL size;
  +        INTVAL value;
  +        SizeIntData *sd;
  +
  +        size = PMC_int_val(SELF);
  +        sd = (SizeIntData *)PMC_data(SELF);
  +
  +        if (sd == NULL || size == 0) {
  +            internal_exception(OUT_OF_BOUNDS, 
  +                    "ResizableIntegerArray: Can't pop from an empty array!");
  +        }
  +
  +     value = sd->data[size - 1];
  +        DYNSELF.set_integer_native(size - 1);
  +
  +        return value;
  +    }
  +
  +/*
  +
   =item C<PMC *clone()>
   
   Creates and returns a copy of the array.
  
  
  
  1.7       +78 -2     parrot/t/pmc/resizableintegerarray.t
  
  Index: resizableintegerarray.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/resizableintegerarray.t,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- resizableintegerarray.t   16 Dec 2004 19:22:46 -0000      1.6
  +++ resizableintegerarray.t   3 Jan 2005 18:44:12 -0000       1.7
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: resizableintegerarray.t,v 1.6 2004/12/16 19:22:46 chromatic Exp $
  +# $Id: resizableintegerarray.t,v 1.7 2005/01/03 18:44:12 scog Exp $
   
   =head1 NAME
   
  @@ -17,7 +17,7 @@
   
   =cut
   
  -use Parrot::Test tests => 9;
  +use Parrot::Test tests => 13;
   use Test::More;
   
   my $fp_equality_macro = <<'ENDOFMACRO';
  @@ -313,3 +313,79 @@
   10001
   10001
   OUTPUT
  +
  +output_is(<<'CODE', <<'OUTPUT', 'basic pop');
  +     new P0, .ResizableIntegerArray
  +     set P0[0], 4
  +     set P0[1], 8
  +     set P0[2], 16
  +     pop I0, P0
  +     eq I0, 16, OK1
  +     print "not "
  +     print I0
  +OK1: print "ok 1\n"
  +
  +     pop I0, P0
  +     eq I0, 8, OK2
  +     print "not "
  +     print I0
  +OK2: print "ok 2\n"
  +
  +     pop I0, P0
  +     eq I0, 4, OK3
  +     print "not "
  +     print I0
  +OK3: print "ok 3\n"
  +     end
  +CODE
  +ok 1
  +ok 2
  +ok 3
  +OUTPUT
  +
  +output_is(<<'CODE', <<'OUTPUT', 'pop many values');
  +     new P0, .ResizableIntegerArray
  +     set I0, 0
  +L1:  set P0[I0], I0
  +     inc I0
  +     lt I0, 100000, L1
  +     
  +L2:  dec I0
  +     pop I1, P0
  +     eq I0, I1, OK
  +     branch NOT_OK
  +OK:  gt I0, 0, L2
  +     print "ok\n"
  +     end
  +
  +NOT_OK:
  +     print I0
  +     print "\n"
  +     print I1
  +     print "\n"
  +     end
  +CODE
  +ok
  +OUTPUT
  +
  +output_is(<<'CODE', <<'OUTPUT', 'push/pop');
  +     new P0, .ResizableIntegerArray
  +     push P0, 2
  +     push P0, 4
  +     push P0, 6
  +     pop I0, P0
  +     eq I0, 6, OK1
  +     print "not "
  +OK1: print "ok 1\n"
  +     end
  +CODE
  +ok 1
  +OUTPUT
  +
  +output_like(<<'CODE', <<'OUTPUT', 'pop from empty array');
  +     new P0, .ResizableIntegerArray
  +     pop I0, P0
  +     end
  +CODE
  +/ResizableIntegerArray: Can't pop from an empty array!/
  +OUTPUT
  
  
  

Reply via email to