2 # Copyright (C) 2001-2010, Parrot Foundation.
7 t/pmc/fixedfloatarray.t - FixedFloatArray PMC
11 % prove t/pmc/fixedfloatarray.t
15 Tests C<FixedFloatArray> PMC. Checks size, sets various elements, including
16 out-of-bounds test. Checks INT and PMC keys.
21 .include 'fp_equality.pasm'
22 .include 'test_more.pir'
34 test_invalid_init_tt1509()
38 $P0 = new ['FixedFloatArray']
41 is($I0, 0, "initial size is 0")
45 is($I0, 1, "changed size is 1")
50 ok(0, "no exception when changing size")
53 ok(1, "exception thrown when changing size")
58 .sub element_set_tests
59 $P0 = new ['FixedFloatArray']
74 $P0 = new ['FixedFloatArray']
92 $P0 = new ['FixedFloatArray']
98 ok(0, "no exception raised when setting nonexistant element")
101 ok(1, "exception raised when setting nonexistant element")
107 ok(0, "no exception raised when getting nonexistant element")
110 ok(1, "exception raised when getting nonexistant element")
115 .sub set_and_get_tests
116 $P0 = new ['FixedFloatArray']
125 set $P0[$P1], "17.32"
128 is($I0, 25, "set int via PMC Key, get via int")
131 .fp_eq($N0, 2.5, ok1)
132 ok(0, "set num via PMC Key, get via int")
135 ok(1, "set num via PMC Key, get via int")
139 is($S0, "17.32", "set string via PMC Key, get via int")
142 $P0 = new ['FixedFloatArray']
148 $P1 = new ['Integer']
155 is($I0, 125, "set int via int, get via PMC Key")
159 .fp_eq($N0, 10.2, ok2)
160 ok(0, "set num via int, get via PMC Key")
163 ok(1, "set num via int, get via PMC Key")
168 is($S0, "17.3", "set string via int, get via PMC Key")
173 is($I1, 123456, "set PMC via int, get via PMC Key")
179 $P0 = new ['FixedFloatArray']
184 L0: is($I1, 1, "clone of empty is empty")
198 .fp_ne($N0, $N1, BAD)
200 ok(1, "clone made a good clone")
204 ok(0, "clone made an evil clone")
212 $P0 = new ['FixedFloatArray']
214 is($I0, 0, "an empty FixedFloatArray is false")
217 is($I0, 1, "a non-empty FixedFloatArray is true")
223 p = new ['FixedFloatArray']
226 is(b, 0, "FFA does not do scalar")
228 is(b, 1, "FFA does array")
229 does b, p, "no_interface"
230 is(b, 0, "FFA does not do no_interface")
234 $P0 = new ['FixedFloatArray']
241 unless $P1 goto loop_end
243 $S0 = concat $S0, $S2
244 $S0 = concat $S0, ","
247 is($S0, "1.1,99.99,-345.001,", "get_iter works")
250 .sub test_new_style_init
251 $P0 = new 'FixedFloatArray', 10
254 is($I0, 10, "New style init creates the correct # of elements")
256 $P0 = new ['FixedFloatArray'], 10
259 is($I0, 10, "New style init creates the correct # of elements for a key constant")
262 .sub test_invalid_init_tt1509
263 throws_substring(<<'CODE', 'FixedFloatArray: Cannot set array size to a negative number (-10)', 'New style init does not dump core for negative array lengths')
265 $P0 = new ['FixedFloatArray'], -10
269 throws_substring(<<'CODE', 'FixedFloatArray: Cannot set array size to a negative number (-10)', 'New style init (key constant) does not dump core for negative array lengths')
271 $P0 = new 'FixedFloatArray', -10
280 # vim: expandtab shiftwidth=4 ft=pir: