Ticket #1000: resizablefloatarray.t_to_pir.patch

File resizablefloatarray.t_to_pir.patch, 18.0 KB (added by flh, 12 years ago)
  • t/pmc/resizablefloatarray.t

     
    1 #! perl 
     1#! parrot 
    22# Copyright (C) 2001-2008, Parrot Foundation. 
    33# $Id$ 
    44 
    5 use strict; 
    6 use warnings; 
    7 use lib qw( . lib ../lib ../../lib ); 
    8 use Test::More; 
    9 use Parrot::Test tests => 22; 
    10  
    115=head1 NAME 
    126 
    137t/pmc/resizablefloatarray.t - ResizableFloatArray PMC 
     
    2317 
    2418=cut 
    2519 
    26 pasm_output_is( <<'CODE', <<'OUTPUT', 'creation' ); 
    27     new P0, ['ResizableFloatArray'] 
    28     print "ok\n" 
    29     end 
    30 CODE 
    31 ok 
    32 OUTPUT 
     20.const int TESTS = 55 
     21.const num PRECISION = 1e-6 
    3322 
    34 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting array size" ); 
    35     new P0, ['ResizableFloatArray'] 
     23.sub 'test' :main 
     24    .include 'test_more.pir' 
     25    .include 'fp_equality.pasm' 
    3626 
    37     set I0,P0 
    38     eq I0,0,OK_1 
    39     print "not " 
    40 OK_1:    print "ok 1\n" 
     27    plan(TESTS) 
    4128 
    42     set P0,1 
    43     set I0,P0 
    44     eq I0,1,OK_2 
    45     print "not " 
    46 OK_2:    print "ok 2\n" 
     29    creation() 
     30    setting_size() 
     31    negative_size() 
     32    setting_first_element() 
     33    setting_second_element() 
     34    setting_negative_index() 
     35    getting_negative_index() 
     36    setting_out_of_bounds() 
     37    getting_out_of_bounds() 
     38    set_pmc_get_int() 
     39    set_int_get_pmc() 
     40    basic_push() 
     41    push_many_values() 
     42    basic_pop() 
     43    pop_many_values() 
     44    push_pop() 
     45    pop_empty() 
     46    shift_empty() 
     47    push_float() 
     48    shift_float() 
     49    unshift_float() 
     50    check_interface() 
     51    get_iter() 
     52    'clone'() 
     53.end 
    4754 
    48     set P0,5 
    49     set I0,P0 
    50     eq I0,5,OK_3 
    51     print "not " 
    52 OK_3:    print "ok 3\n" 
     55.sub 'creation' 
     56    $P0 = new ['ResizableFloatArray'] 
     57    ok(1, 'creation') 
     58.end 
    5359 
    54     set P0,9 
    55     set I0,P0 
    56     eq I0,9,OK_4 
    57     print "not " 
    58 OK_4:    print "ok 4\n" 
     60.sub 'setting_size' 
     61    $P0 = new ['ResizableFloatArray'] 
    5962 
    60     set P0,7 
    61     set I0,P0 
    62     eq I0,7,OK_5 
    63     print "not " 
    64 OK_5:    print "ok 5\n" 
     63    $I0 = $P0 
     64    is($I0, 0, 'size is initially 0') 
    6565 
    66         end 
    67 CODE 
    68 ok 1 
    69 ok 2 
    70 ok 3 
    71 ok 4 
    72 ok 5 
    73 OUTPUT 
     66    $P0 = 1 
     67    $I0 = $P0 
     68    is($I0, 1, 'setting size to 1') 
    7469 
    75 pasm_error_output_like( <<'CODE', <<'OUTPUT', "Setting negative array size" ); 
    76     new P0, ['ResizableFloatArray'] 
    77         set P0, -100 
    78         end 
    79 CODE 
    80 /ResizableFloatArray: Can't resize to negative value!/ 
    81 OUTPUT 
     70    $P0 = 5 
     71    $I0 = $P0 
     72    is($I0, 5, 'resizing to 5') 
    8273 
    83 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting first element" ); 
    84     new P0, ['ResizableFloatArray'] 
    85     set P0, 1 
     74    $P0 = 9 
     75    $I0 = $P0 
     76    is($I0, 9, 'resizing to 9') 
    8677 
    87     set P0[0],-7 
    88     set I0,P0[0] 
    89     eq I0,-7,OK_1 
    90     print "not " 
    91 OK_1:    print "ok 1\n" 
     78    $P0 = 7 
     79    $I0 = $P0 
     80    is($I0, 7, 'resizing to 7') 
     81.end 
    9282 
    93     set P0[0],3.7 
    94     set N0,P0[0] 
    95     eq N0,3.7,OK_2 
    96     print "not " 
    97 OK_2:    print "ok 2\n" 
     83.sub 'negative_size' 
     84    $P0 = new ['ResizableFloatArray'] 
    9885 
    99     set P0[0],"17.2" 
    100     set S0,P0[0] 
    101     eq S0,"17.2",OK_3 
    102     print "not " 
    103 OK_3:    print "ok 3\n" 
     86    push_eh negative_size_handler 
     87    $P0 = -100 
     88    pop_eh 
     89    nok(1, 'setting negative array size') 
     90    .return() 
    10491 
    105     end 
    106 CODE 
    107 ok 1 
    108 ok 2 
    109 ok 3 
    110 OUTPUT 
     92  negative_size_handler: 
     93    .get_results ($P1) 
     94    $S1 = $P1 
     95    like($S1, ":s ResizableFloatArray\\: Can\\'t resize to negative value\\!", 'setting negative array size') 
     96.end 
    11197 
    112 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting second element" ); 
    113     new P0, ['ResizableFloatArray'] 
     98.sub 'setting_first_element' 
     99    $P0 = new ['ResizableFloatArray'] 
     100    $P0 = 1 
    114101 
    115     set P0[1], -7 
    116     set I0, P0[1] 
    117     eq I0,-7,OK_1 
    118     print "not " 
    119 OK_1:    print "ok 1\n" 
     102    $P0[0] = -7 
     103    $I0 = $P0[0] 
     104    is($I0, -7, 'setting first element from int') 
    120105 
    121     set P0[1], 3.7 
    122     set N0, P0[1] 
    123     eq N0,3.7,OK_2 
    124     print "not " 
    125 OK_2:    print "ok 2\n" 
     106    $P0[0] = 3.7 
     107    $N0 = $P0[0] 
     108    is($N0, 3.7, 'setting first element from number') 
    126109 
    127     set P0[1],"17.1" 
    128     set S0, P0[1] 
    129     eq S0,"17.1",OK_3 
    130     print "not " 
    131 OK_3:    print "ok 3\n" 
     110    $P0[0] = "17.2" 
     111    $S0 = $P0[0] 
     112    is($S0, "17.2", 'setting first element from string') 
     113.end 
    132114 
    133     end 
    134 CODE 
    135 ok 1 
    136 ok 2 
    137 ok 3 
    138 OUTPUT 
     115.sub 'setting_second_element' 
     116    $P0 = new ['ResizableFloatArray'] 
    139117 
    140 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting negatively indexed elements" ); 
    141     new P0, ['ResizableFloatArray'] 
    142     set P0, 1 
     118    $P0[1] = -7 
     119    $I0 = $P0[1] 
     120    is($I0, -7, 'setting second element from int') 
    143121 
    144     push_eh caught 
    145     set P0[-1], -7 
     122    $P0[1] = 3.7 
     123    $N0 = $P0[1] 
     124    is($N0, 3.7, 'setting second element from number') 
     125 
     126    $P0[1] = "17.1" 
     127    $S0 = $P0[1] 
     128    is($S0, "17.1", 'setting second element from string') 
     129.end 
     130 
     131.sub 'setting_negative_index' 
     132    $P0 = new ['ResizableFloatArray'] 
     133    $P0 = 1 
     134 
     135    push_eh setting_negative_index_handler 
     136    $P0[-1] = -7 
    146137    pop_eh 
    147     print "no exception\n" 
    148     end 
    149 caught: 
    150     say "caught something" 
    151     end 
    152 CODE 
    153 caught something 
    154 OUTPUT 
     138    nok(1, 'setting negatively indexed elements') 
     139    .return () 
    155140 
    156 pasm_output_is( <<'CODE', <<'OUTPUT', "Getting negatively indexed elements" ); 
    157     new P0, ['ResizableFloatArray'] 
    158     set P0, 1 
     141  setting_negative_index_handler: 
     142    ok(1, 'setting negatively indexed elements') 
     143.end 
    159144 
    160     push_eh caught 
    161     set I0, P0[-1] 
     145.sub 'getting_negative_index' 
     146    $P0 = new ['ResizableFloatArray'] 
     147    $P0 = 1 
     148 
     149    push_eh getting_negative_index_handler 
     150    $I0 = $P0[-1] 
    162151    pop_eh 
    163     say "no exception" 
    164     end 
    165 caught: 
    166     say "caught an exception" 
    167     end 
    168 CODE 
    169 caught an exception 
    170 OUTPUT 
     152    nok(1, 'getting negatively indexed elements') 
     153    .return () 
    171154 
    172 pasm_output_is( <<'CODE', <<'OUTPUT', "Setting out-of-bounds elements" ); 
    173     new P0, ['ResizableFloatArray'] 
    174     set P0, 1 
     155  getting_negative_index_handler: 
     156    ok(1, 'getting negatively indexed elements') 
     157.end 
    175158 
    176     set P0[1], -7 
    177     print "ok 1\n" 
     159.sub 'setting_out_of_bounds' 
     160    $P0 = new ['ResizableFloatArray'] 
     161    $P0 = 1 
    178162 
    179     end 
    180 CODE 
    181 ok 1 
    182 OUTPUT 
     163    $P0[1] = -7 
     164    ok(1, 'setting out-of-bounds elements') 
     165.end 
    183166 
    184 pasm_output_is( <<'CODE', <<'OUTPUT', "Getting out-of-bounds elements" ); 
    185     new P0, ['ResizableFloatArray'] 
    186     set P0, 1 
     167.sub 'getting_out_of_bounds' 
     168    $P0 = new ['ResizableFloatArray'] 
     169    $P0 = 1 
    187170 
    188     set I0, P0[1] 
    189     print "ok 1\n" 
    190     end 
    191 CODE 
    192 ok 1 
    193 OUTPUT 
     171    $I0 = $P0[1] 
     172    ok(1, 'getting out-of-bounds elements') 
     173.end 
    194174 
    195 pasm_output_is( <<"CODE", <<'OUTPUT', "Set via PMC keys, access via INTs" ); 
    196      .include 'fp_equality.pasm' 
    197      new P0, ['ResizableFloatArray'] 
    198      new P1, ['Key'] 
     175.sub 'set_pmc_get_int' 
     176    $P0 = new ['ResizableFloatArray'] 
     177    $P1 = new ['Key'] 
    199178 
    200      set P1, 0 
    201      set P0[P1], 25 
     179    $P1 = 0 
     180    $P0[$P1] = 25 
    202181 
    203      set P1, 1 
    204      set P0[P1], 2.5 
     182    $P1 = 1 
     183    $P0[$P1] = 2.5 
    205184 
    206      set P1, 2 
    207      set P0[P1], "17.32" 
     185    $P1 = 2 
     186    $P0[$P1] = "17.32" 
    208187 
    209      set I0, P0[0] 
    210      eq I0, 25, OK1 
    211      print "not " 
    212 OK1: print "ok 1\\n" 
     188    $I0 = $P0[0] 
     189    is($I0, 25, 'Set via PMC keys, access via INTs (1)') 
    213190 
    214      set N0, P0[1] 
    215      .fp_eq_pasm(N0, 2.5, OK2) 
    216      print "not " 
    217 OK2: print "ok 2\\n" 
     191    $N0 = $P0[1] 
     192    is($N0, 2.5, 'Set via PMC keys, access via INTs (2)', PRECISION) 
    218193 
    219      set S0, P0[2] 
    220      eq S0, "17.32", OK3 
    221      print "not " 
    222 OK3: print "ok 3\\n" 
     194    $S0 = $P0[2] 
     195    is($S0, "17.32", 'Set via PMC keys, access via INTs (3)') 
     196.end 
    223197 
    224      end 
    225 CODE 
    226 ok 1 
    227 ok 2 
    228 ok 3 
    229 OUTPUT 
     198.sub 'set_int_get_pmc' 
     199    $P0 = new ['ResizableFloatArray'] 
     200    $P0 = 1 
    230201 
    231 pasm_output_is( <<"CODE", <<'OUTPUT', "Set via INTs, access via PMC Keys" ); 
    232      .include 'fp_equality.pasm' 
    233      new P0, ['ResizableFloatArray'] 
    234      set P0, 1 
     202    $P0[25] = 125 
     203    $P0[128] = 10.2 
     204    $P0[513] = "17.3" 
     205    $P1 = new ['Integer'] 
     206    $P1 = 123456 
     207    $P0[1023] = $P1 
    235208 
    236      set P0[25], 125 
    237      set P0[128], 10.2 
    238      set P0[513], "17.3" 
    239      new P1, ['Integer'] 
    240      set P1, 123456 
    241      set P0[1023], P1 
     209    $P2 = new ['Key'] 
    242210 
    243      new P2, ['Key'] 
    244      set P2, 25 
    245      set I0, P0[P2] 
    246      eq I0, 125, OK1 
    247      print "not " 
    248 OK1: print "ok 1\\n" 
     211    $P2 = 25 
     212    $I0 = $P0[$P2] 
     213    is($I0, 125, 'Set via INTs, access via PMC Keys (1)') 
    249214 
    250      set P2, 128 
    251      set N0, P0[P2] 
    252      .fp_eq_pasm(N0, 10.2, OK2) 
    253      print "not " 
    254 OK2: print "ok 2\\n" 
     215    $P2 = 128 
     216    $N0 = $P0[$P2] 
     217    is($N0, 10.2, 'Set via INTs, access via PMC Keys (2)', PRECISION) 
    255218 
    256      set P2, 513 
    257      set S0, P0[P2] 
    258      eq S0, "17.3", OK3 
    259      print "not " 
    260 OK3: print "ok 3\\n" 
     219    $P2 = 513 
     220    $S0 = $P0[$P2] 
     221    is($S0, "17.3", 'Set via INTs, access via PMC Keys (3)') 
    261222 
    262      set P2, 1023 
    263      set P3, P0[P2] 
    264      set I1, P3 
    265      eq I1, 123456, OK4 
    266      print "not " 
    267 OK4: print "ok 4\\n" 
     223    $P2 = 1023 
     224    $I0 = $P0[$P2] 
     225    is($I0, 123456, 'Set via INTs, access via PMC Keys (4)') 
     226.end 
    268227 
    269      end 
    270 CODE 
    271 ok 1 
    272 ok 2 
    273 ok 3 
    274 ok 4 
    275 OUTPUT 
     228.sub 'basic_push' 
     229    $P0 = new ['ResizableFloatArray'] 
     230    push $P0, 1.0 
     231    push $P0, 2.0 
     232    push $P0, 3.0 
    276233 
    277 pasm_output_is( <<"CODE", <<'OUTPUT', 'basic push' ); 
    278      .include 'fp_equality.pasm' 
    279      new P0, ['ResizableFloatArray'] 
    280      push P0, 1.0 
    281      push P0, 2.0 
    282      push P0, 3.0 
    283      set N0, P0[0] 
    284      .fp_eq_pasm(N0, 1.0, OK1) 
    285      print "not " 
    286 OK1: print "ok 1\\n" 
     234    $N0 = $P0[0] 
     235    is($N0, 1.0, 'basic push (1)', PRECISION) 
    287236 
    288      set N0, P0[1] 
    289      .fp_eq_pasm(N0, 2.0, OK2) 
    290      print "not " 
    291 OK2: print "ok 2\\n" 
     237    $N0 = $P0[1] 
     238    is($N0, 2.0, 'basic push (2)', PRECISION) 
    292239 
    293      set N0, P0[2] 
    294      .fp_eq_pasm(N0, 3.0, OK3) 
    295      print "not " 
    296 OK3: print "ok 3\\n" 
    297      end 
    298 CODE 
    299 ok 1 
    300 ok 2 
    301 ok 3 
    302 OUTPUT 
     240    $N0 = $P0[2] 
     241    is($N0, 3.0, 'basic push (3)', PRECISION) 
     242.end 
    303243 
    304 pasm_output_is( <<"CODE", <<'OUTPUT', 'push many values' ); 
    305      .include 'fp_equality.pasm' 
    306      new P0, ['ResizableFloatArray'] 
    307      set I0, 0 
    308 L1:  set N0, I0 
    309      push P0, N0 
    310      inc I0 
    311      lt I0, 100000, L1 
     244.sub 'push_many_values' 
     245    $P0 = new ['ResizableFloatArray'] 
    312246 
    313      set N0, P0[99999] 
    314      .fp_eq_pasm(N0, 99999.0, OK1) 
    315      print N0 
    316      print "not " 
    317 OK1: print "ok 1\\n" 
    318      end 
    319 CODE 
    320 ok 1 
    321 OUTPUT 
     247    $I0 = 0 
     248  push_many_values_fill: 
     249    $N0 = $I0 
     250    push $P0, $N0 
     251    inc $I0 
     252    if $I0 < 100000 goto push_many_values_fill 
    322253 
    323 pasm_output_is( <<"CODE", <<'OUTPUT', 'basic pop' ); 
    324      .include 'fp_equality.pasm' 
    325      new P0, ['ResizableFloatArray'] 
    326      set P0[0], 1.0 
    327      set P0[1], 2.0 
    328      set P0[2], 3.0 
    329      pop N0, P0 
    330      .fp_eq_pasm(N0, 3.0, OK1) 
    331      print "not " 
    332 OK1: print "ok 1\\n" 
     254  push_many_values_test: 
     255    dec $I0 
     256    $N0 = $I0 
     257    $N1 = $P0[$I0] 
     258    .fp_ne($N0, $N1, push_many_values_evil) 
     259    if $I0 > 0 goto push_many_values_test 
    333260 
    334      pop N0, P0 
    335      .fp_eq_pasm(N0, 2.0, OK2) 
    336      print "not " 
    337 OK2: print "ok 2\\n" 
     261    ok(1, 'push many values') 
     262    .return () 
    338263 
    339      pop N0, P0 
    340      .fp_eq_pasm(N0, 1.0, OK3) 
    341      print "not " 
    342 OK3: print "ok 3\\n" 
    343      end 
    344 CODE 
    345 ok 1 
    346 ok 2 
    347 ok 3 
    348 OUTPUT 
     264  push_many_values_evil: 
     265    nok(1, 'push many values is evil') 
     266.end 
    349267 
    350 pasm_output_is( <<"CODE", <<'OUTPUT', 'pop many values' ); 
    351      .include 'fp_equality.pasm' 
    352      new P0, ['ResizableFloatArray'] 
    353      set I0, 0 
    354 L1:  set N0, I0 
    355      set P0[I0], N0 
    356      inc I0 
    357      lt I0, 100000, L1 
     268.sub 'basic_pop' 
     269    $P0 = new ['ResizableFloatArray'] 
     270    $P0[0] = 1.0 
     271    $P0[1] = 2.0 
     272    $P0[2] = 3.0 
    358273 
    359 L2:  dec I0 
    360      set N1, I0 
    361      pop N0, P0 
    362      .fp_eq_pasm(N0, N1, OK) 
    363      branch NOT_OK 
    364 OK:  gt I0, 0, L2 
    365      print "ok\\n" 
    366      end 
     274    $N0 = pop $P0 
     275    is($N0, 3.0, 'basic pop (1)', PRECISION) 
    367276 
    368 NOT_OK: 
    369      print N0 
    370      print "\\n" 
    371      print N1 
    372      print "\\n" 
    373      end 
    374 CODE 
    375 ok 
    376 OUTPUT 
     277    $N0 = pop $P0 
     278    is($N0, 2.0, 'basic pop (2)', PRECISION) 
    377279 
    378 pasm_output_is( <<"CODE", <<'OUTPUT', 'push/pop' ); 
    379      .include 'fp_equality.pasm' 
    380      new P0, ['ResizableFloatArray'] 
    381      push P0, 1.0 
    382      push P0, 2.0 
    383      push P0, 3.0 
    384      pop N0, P0 
    385      .fp_eq_pasm(N0, 3.0, OK1) 
    386      print "not " 
    387 OK1: print "ok 1\\n" 
    388      end 
    389 CODE 
    390 ok 1 
    391 OUTPUT 
     280    $N0 = pop $P0 
     281    is($N0, 1.0, 'basic pop (3)', PRECISION) 
     282.end 
    392283 
    393 pasm_error_output_like( <<'CODE', <<'OUTPUT', 'pop from empty array' ); 
    394      new P0, ['ResizableFloatArray'] 
    395      pop N0, P0 
    396      end 
    397 CODE 
    398 /ResizableFloatArray: Can't pop from an empty array!/ 
    399 OUTPUT 
     284.sub 'pop_many_values' 
     285    $P0 = new ['ResizableFloatArray'] 
    400286 
    401 pir_output_is( << 'CODE', << 'OUTPUT', "check whether interface is done" ); 
     287    $I0 = 0 
     288  pop_many_values_fill: 
     289    $N0 = $I0 
     290    $P0[$I0] = $N0 
     291    inc $I0 
     292    if $I0 < 100000 goto pop_many_values_fill 
    402293 
    403 .sub _main 
    404     .local pmc pmc1 
    405     pmc1 = new ['ResizableFloatArray'] 
    406     .local int bool1 
    407     does bool1, pmc1, "scalar" 
    408     print bool1 
    409     print "\n" 
    410     does bool1, pmc1, "array" 
    411     print bool1 
    412     print "\n" 
    413     does bool1, pmc1, "no_interface" 
    414     print bool1 
    415     print "\n" 
    416     end 
     294  pop_many_values_test: 
     295    dec $I0 
     296    $N0 = $I0 
     297    $N1 = pop $P0 
     298    .fp_ne($N0, $N1, pop_many_values_evil) 
     299    if $I0 > 0 goto pop_many_values_test 
     300 
     301    ok(1, 'pop many values') 
     302    .return () 
     303 
     304  pop_many_values_evil: 
     305    nok(1, 'pop many values is evil') 
    417306.end 
    418 CODE 
    419 0 
    420 1 
    421 0 
    422 OUTPUT 
    423307 
    424 pir_output_is( << 'CODE', << 'OUTPUT', "push float" ); 
     308.sub 'push_pop' 
     309    $P0 = new ['ResizableFloatArray'] 
     310    push $P0, 1.0 
     311    push $P0, 2.0 
     312    push $P0, 3.0 
    425313 
    426 .sub _main 
    427     .local pmc pmc1 
    428     pmc1 = new ['ResizableFloatArray'] 
    429     pmc1[9999] = 10000.10000 
    430     push pmc1, 123.123 
    431     .local int elements 
    432     elements = pmc1 
    433     print elements 
    434     print "\n" 
    435     .local string last 
    436     last = pmc1[10000] 
    437     print last 
    438     print "\n" 
    439     end 
     314    $N0 = pop $P0 
     315    is($N0, 3.0, 'push/pop (1)') 
     316 
     317    $N0 = pop $P0 
     318    is($N0, 2.0, 'push/pop (2)') 
     319 
     320    $N0 = pop $P0 
     321    is($N0, 1.0, 'push/pop (3)') 
    440322.end 
    441 CODE 
    442 10001 
    443 123.123 
    444 OUTPUT 
    445323 
    446 pir_output_is( << 'CODE', << 'OUTPUT', "shift float" ); 
    447 .sub test :main 
    448     .local pmc ar 
    449     ar = new ['ResizableFloatArray'] 
    450     ar[0] = 10.1 
    451     ar[1] = 20.2 
    452     $I0 = elements ar 
    453     print $I0 
    454     print ' ' 
    455     $N0 = shift ar 
    456     print $N0 
    457     print ' ' 
    458     $I0 = elements ar 
    459     print $I0 
    460     print ' ' 
    461     $N0 = shift ar 
    462     print $N0 
    463     print ' ' 
    464     $I0 = elements ar 
    465     print $I0 
    466     print "\n" 
     324.sub 'pop_empty' 
     325    $P0 = new ['ResizableFloatArray'] 
     326 
     327    push_eh pop_empty_handler 
     328    $N0 = pop $P0 
     329    pop_eh 
     330    nok(1, 'pop from empty array') 
     331    .return() 
     332 
     333  pop_empty_handler: 
     334    .get_results($P0) 
     335    $S0 = $P0 
     336    like($S0, ":s ResizableFloatArray\\: Can\\'t pop from an empty array\\!", 'pop from empty array') 
    467337.end 
    468 CODE 
    469 2 10.1 1 20.2 0 
    470 OUTPUT 
    471338 
    472 pir_output_is( << 'CODE', << 'OUTPUT', "unshift float" ); 
    473 .sub test :main 
    474     .local pmc ar 
    475     ar = new ['ResizableFloatArray'] 
    476     unshift ar, 10.1 
    477     unshift ar, 20.2 
    478     $I0 = elements ar 
    479     print $I0 
    480     print ' ' 
    481     $N0 = ar[0] 
    482     print $N0 
    483     print ' ' 
    484     $N0 = ar[1] 
    485     print $N0 
    486     print "\n" 
     339.sub 'shift_empty' 
     340    $P0 = new ['ResizableFloatArray'] 
     341 
     342    push_eh shift_empty_handler 
     343    $N0 = shift $P0 
     344    pop_eh 
     345    nok(1, 'shift from empty array') 
     346    .return() 
     347 
     348  shift_empty_handler: 
     349    .get_results($P0) 
     350    $S0 = $P0 
     351    like($S0, ":s ResizableFloatArray\\: Can\\'t shift from an empty array\\!", 'shift from empty array') 
    487352.end 
    488 CODE 
    489 2 20.2 10.1 
    490 OUTPUT 
    491353 
    492 pir_output_is( << 'CODE', << 'OUTPUT', "get_iter" ); 
    493 .sub main :main 
     354.sub 'check_interface' 
    494355    $P0 = new ['ResizableFloatArray'] 
     356 
     357    $I0 = does $P0, 'scalar' 
     358    nok($I0, 'ResizableFloatArray does not scalar') 
     359 
     360    $I0 = does $P0, 'array' 
     361    ok($I0, 'ResizableFloatArray does array') 
     362 
     363    $I0 = does $P0, 'no_interface' 
     364    nok($I0, 'ResizableFloatArray does not no_interface') 
     365.end 
     366 
     367.sub 'push_float' 
     368    $P0 = new ['ResizableFloatArray'] 
     369    $P0[9999] = 10000.10000 
     370    push $P0, 123.123 
     371 
     372    $I0 = elements $P0 
     373    is($I0, 10001, 'push float: size') 
     374 
     375    $N0 = $P0[10000] 
     376    is($N0, 123.123, 'push float: test pushed element', PRECISION) 
     377.end 
     378 
     379.sub 'shift_float' 
     380    $P0 = new ['ResizableFloatArray'] 
     381    $P0[0] = 10.1 
     382    $P0[1] = 20.2 
     383 
     384    $I0 = elements $P0 
     385    is($I0, 2, 'shift float: size') 
     386 
     387    $N0 = shift $P0 
     388    is($N0, 10.1, 'shift float: first element', PRECISION) 
     389 
     390    $N0 = shift $P0 
     391    is($N0, 20.2, 'shift float: second element', PRECISION) 
     392 
     393    $I0 = elements $P0 
     394    is($I0, 0, 'shift float: array now empty') 
     395.end 
     396 
     397.sub 'unshift_float' 
     398    $P0 = new ['ResizableFloatArray'] 
     399    unshift $P0, 10.1 
     400    unshift $P0, 20.2 
     401 
     402    $I0 = elements $P0 
     403    is($I0, 2, 'unshift float: size') 
     404 
     405    $N0 = $P0[0] 
     406    is($N0, 20.2, 'unshift float: first element', PRECISION) 
     407 
     408    $N0 = $P0[1] 
     409    is($N0, 10.1, 'unshift float: second element', PRECISION) 
     410.end 
     411 
     412.sub 'get_iter' 
     413    $P0 = new ['ResizableFloatArray'] 
    495414    $P0[0] = 1.1 
    496415    $P0[1] = 99.99 
    497416    $P0[2] = -345.001 
     417 
    498418    $P1 = iter $P0 
    499 loop: 
    500     unless $P1 goto loop_end 
    501     $S2 = shift $P1 
    502     say $S2 
    503     goto loop 
    504   loop_end: 
     419 
     420    $N0 = shift $P1 
     421    is($N0, 1.1, 'get_iter: first element ok', PRECISION) 
     422 
     423    $N0 = shift $P1 
     424    is($N0, 99.99, 'get_iter: second element ok', PRECISION) 
     425 
     426    $N0 = shift $P1 
     427    is($N0, -345.001, 'get_iter: third element ok', PRECISION) 
     428 
     429    nok($P1, 'get_iter: iterator emptied') 
    505430.end 
    506 CODE 
    507 1.1 
    508 99.99 
    509 -345.001 
    510 OUTPUT 
    511431 
     432.sub 'clone' 
     433    .local int i 
     434    $P0 = new ['ResizableFloatArray'] 
     435 
     436    $I30 = 3000 
     437    i = 0 
     438  clone_fill: 
     439    unless i < $I30 goto clone_filled 
     440    $N0 = i + 0.01 
     441    $P0[i] = $N0 
     442    inc i 
     443    goto clone_fill 
     444 
     445  clone_filled: 
     446    $P1 = clone $P0 
     447    $I0 = $P0 
     448    $I1 = $P1 
     449    is($I0, $I1, 'clones have the same size') 
     450 
     451  clone_iter_loop: 
     452    dec $I0 
     453    $N0 = $P1[$I0] 
     454    $N1 = $I0 + 0.01 
     455    .fp_ne($N0, $N1, clone_evil) 
     456    if $I0 > 0 goto clone_iter_loop 
     457 
     458    ok(1, 'clone make a good clone') 
     459    .return() 
     460 
     461  clone_evil: 
     462    nok(0, 'clone made an evil clone') 
     463.end 
     464 
    512465# Local Variables: 
    513 #   mode: cperl 
    514 #   cperl-indent-level: 4 
     466#   mode: pir 
    515467#   fill-column: 100 
    516468# End: 
    517 # vim: expandtab shiftwidth=4: 
     469# vim: expandtab shiftwidth=4 ft=pir: