2 # Copyright (C) 2001-2009, Parrot Foundation.
7 t/pmc/resizablefloatarray.t - ResizableFloatArray PMC
11 % prove t/pmc/resizablefloatarray.t
15 Tests C<ResizableFloatArray> PMC. Checks size, sets various elements, including
16 out-of-bounds test. Checks INT and PMC keys.
21 .const num PRECISION = 1e-6
24 .include 'test_more.pir'
25 .include 'fp_equality.pasm'
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()
56 $P0 = new ['ResizableFloatArray']
61 $P0 = new ['ResizableFloatArray']
64 is($I0, 0, 'size is initially 0')
68 is($I0, 1, 'setting size to 1')
72 is($I0, 5, 'resizing to 5')
76 is($I0, 9, 'resizing to 9')
80 is($I0, 7, 'resizing to 7')
84 $P0 = new ['ResizableFloatArray']
86 push_eh negative_size_handler
89 nok(1, 'setting negative array size')
92 negative_size_handler:
94 ok(1, "cannot set negative array size")
97 .sub 'setting_first_element'
98 $P0 = new ['ResizableFloatArray']
103 is($I0, -7, 'setting first element from int')
107 is($N0, 3.7, 'setting first element from number')
111 is($S0, "17.2", 'setting first element from string')
114 .sub 'setting_second_element'
115 $P0 = new ['ResizableFloatArray']
119 is($I0, -7, 'setting second element from int')
123 is($N0, 3.7, 'setting second element from number')
127 is($S0, "17.1", 'setting second element from string')
130 .sub 'setting_negative_index'
131 $P0 = new ['ResizableFloatArray']
134 push_eh setting_negative_index_handler
137 nok(1, 'setting negatively indexed elements')
140 setting_negative_index_handler:
141 ok(1, 'setting negatively indexed elements')
144 .sub 'getting_negative_index'
145 $P0 = new ['ResizableFloatArray']
148 push_eh getting_negative_index_handler
151 nok(1, 'getting negatively indexed elements')
154 getting_negative_index_handler:
155 ok(1, 'getting negatively indexed elements')
158 .sub 'setting_out_of_bounds'
159 $P0 = new ['ResizableFloatArray']
163 ok(1, 'setting out-of-bounds elements')
166 .sub 'getting_out_of_bounds'
167 $P0 = new ['ResizableFloatArray']
171 ok(1, 'getting out-of-bounds elements')
174 .sub 'set_pmc_get_int'
175 $P0 = new ['ResizableFloatArray']
188 is($I0, 25, 'Set via PMC keys, access via INTs (1)')
191 is($N0, 2.5, 'Set via PMC keys, access via INTs (2)', PRECISION)
194 is($S0, "17.32", 'Set via PMC keys, access via INTs (3)')
197 .sub 'set_int_get_pmc'
198 $P0 = new ['ResizableFloatArray']
204 $P1 = new ['Integer']
212 is($I0, 125, 'Set via INTs, access via PMC Keys (1)')
216 is($N0, 10.2, 'Set via INTs, access via PMC Keys (2)', PRECISION)
220 is($S0, "17.3", 'Set via INTs, access via PMC Keys (3)')
224 is($I0, 123456, 'Set via INTs, access via PMC Keys (4)')
228 $P0 = new ['ResizableFloatArray']
234 is($N0, 1.0, 'basic push (1)', PRECISION)
237 is($N0, 2.0, 'basic push (2)', PRECISION)
240 is($N0, 3.0, 'basic push (3)', PRECISION)
243 .sub 'push_many_values'
244 $P0 = new ['ResizableFloatArray']
247 push_many_values_fill:
251 if $I0 < 100000 goto push_many_values_fill
253 push_many_values_test:
257 .fp_ne($N0, $N1, push_many_values_evil)
258 if $I0 > 0 goto push_many_values_test
260 ok(1, 'push many values')
263 push_many_values_evil:
264 nok(1, 'push many values is evil')
268 $P0 = new ['ResizableFloatArray']
274 is($N0, 3.0, 'basic pop (1)', PRECISION)
277 is($N0, 2.0, 'basic pop (2)', PRECISION)
280 is($N0, 1.0, 'basic pop (3)', PRECISION)
283 .sub 'pop_many_values'
284 $P0 = new ['ResizableFloatArray']
287 pop_many_values_fill:
291 if $I0 < 100000 goto pop_many_values_fill
293 pop_many_values_test:
297 .fp_ne($N0, $N1, pop_many_values_evil)
298 if $I0 > 0 goto pop_many_values_test
300 ok(1, 'pop many values')
303 pop_many_values_evil:
304 nok(1, 'pop many values is evil')
308 $P0 = new ['ResizableFloatArray']
314 is($N0, 3.0, 'push/pop (1)')
317 is($N0, 2.0, 'push/pop (2)')
320 is($N0, 1.0, 'push/pop (3)')
324 $P0 = new ['ResizableFloatArray']
326 push_eh pop_empty_handler
329 nok(1, 'pop from empty array')
334 ok(1, "cannot pop from empty array")
338 $P0 = new ['ResizableFloatArray']
340 push_eh shift_empty_handler
343 nok(1, 'shift from empty array')
348 ok(1, "cannot shift from empty array")
351 .sub 'check_interface'
352 $P0 = new ['ResizableFloatArray']
354 $I0 = does $P0, 'scalar'
355 nok($I0, 'ResizableFloatArray does not scalar')
357 $I0 = does $P0, 'array'
358 ok($I0, 'ResizableFloatArray does array')
360 $I0 = does $P0, 'no_interface'
361 nok($I0, 'ResizableFloatArray does not no_interface')
365 $P0 = new ['ResizableFloatArray']
366 $P0[9999] = 10000.10000
370 is($I0, 10001, 'push float: size')
373 is($N0, 123.123, 'push float: test pushed element', PRECISION)
377 $P0 = new ['ResizableFloatArray']
382 is($I0, 2, 'shift float: size')
385 is($N0, 10.1, 'shift float: first element', PRECISION)
388 is($N0, 20.2, 'shift float: second element', PRECISION)
391 is($I0, 0, 'shift float: array now empty')
395 $P0 = new ['ResizableFloatArray']
400 is($I0, 2, 'unshift float: size')
403 is($N0, 20.2, 'unshift float: first element', PRECISION)
406 is($N0, 10.1, 'unshift float: second element', PRECISION)
410 $P0 = new ['ResizableFloatArray']
418 is($N0, 1.1, 'get_iter: first element ok', PRECISION)
421 is($N0, 99.99, 'get_iter: second element ok', PRECISION)
424 is($N0, -345.001, 'get_iter: third element ok', PRECISION)
426 nok($P1, 'get_iter: iterator emptied')
431 $P0 = new ['ResizableFloatArray']
436 unless i < $I30 goto clone_filled
446 is($I0, $I1, 'clones have the same size')
452 .fp_ne($N0, $N1, clone_evil)
453 if $I0 > 0 goto clone_iter_loop
455 ok(1, 'clone make a good clone')
459 nok(0, 'clone made an evil clone')
466 # vim: expandtab shiftwidth=4 ft=pir: