2 # Copyright (C) 2008-2010, Parrot Foundation.
7 t/dynpmc/rational.t - Rational PMC
11 % prove t/dynpmc/rational.t
15 Tests the Rational PMC.
20 .include 'test_more.pir'
21 .include 'iglobals.pasm'
22 .local pmc config_hash, interp
25 config_hash = interp[.IGLOBALS_CONFIG_HASH]
26 $S0 = config_hash['gmp']
28 unless $S0 goto no_gmp
33 # seems like plan(0) is not supported currently
35 ok(1,'GMP not found, skipping Rational tests')
38 # The following tests only run if GMP is installed
40 loadlib $P1, 'rational'
43 test_set_get_native_int()
44 test_set_get_native_float()
45 test_set_get_native_string()
52 test_add_int_inplace()
53 test_add_float_inplace()
55 test_add_int_pmc_inplace()
56 test_add_float_pmc_inplace()
57 test_add_rats_inplace()
61 test_subtract_int_pmc()
66 test_multiply_int_pmc()
67 test_multiply_float_pmc()
73 test_divide_float_pmc()
105 .sub test_equal_tt1517
110 if $P2 == $P3 goto pass
111 ok(0,'== on Rational and Integer PMC')
114 ok(1,'== on Rational and Integer PMC')
124 if $P2 == $P3 goto EQ
127 ok(1,'== on Rational PMC')
130 ok(0,'== on Rational PMC')
136 is($I1,-1,'cmp on Rational PMC')
137 is($I2,1,'cmp on Rational PMC')
148 is($P1,'3/14','divide int')
149 is($P2,'3/14','divide int')
152 .sub test_divide_float
160 is($P1,'3/14','divide float')
161 is($P2,'3/14','divide float')
165 .sub test_divide_int_pmc
175 is($P2,'3/14','divide Integer PMC')
176 is($P3,'3/14','divide Integer PMC')
179 .sub test_divide_float_pmc
189 is($P2,'3/14','divide Float PMC')
190 is($P3,'3/14','divide Float PMC')
193 .sub test_divide_rats
203 is($P1,'3/5','divide Rational PMC')
204 is($P2,'3/5','divide Rational PMC')
207 .sub test_multiply_int
215 is($P1,'21/2','multiply int')
216 is($P2,'21/2','multiply int')
219 .sub test_multiply_float
227 is($P1,'21/2','multiply float')
228 is($P2,'21/2','multiply float')
231 .sub test_multiply_int_pmc
241 is($P2,'21/2','multiply Integer PMC')
242 is($P3,'21/2','multiply Integer PMC')
245 .sub test_multiply_float_pmc
255 is($P2,'21/2','multiply Float PMC')
256 is($P3,'21/2','multiply Float PMC')
260 .sub test_multiply_rats
270 is($P1,'15/4','multiply Rational PMC')
271 is($P2,'15/4','multiply Rational PMC')
274 .sub test_subtract_rats
284 is($P1,-1,'subtract Rational inplace')
285 is($P2,-1,'subtract Rational inplace')
289 .sub test_subtract_int
298 is($P1,'-25/2','subtract int inplace')
299 is($P2,'-11/2','subtract int inplace')
302 .sub test_subtract_float
311 is($P1,'-25/2','subtract float inplace')
312 is($P2,'-11/2','subtract float inplace')
315 .sub test_subtract_int_pmc
325 is($P2,'-11/2','subtract Integer PMC inplace')
326 is($P3,'-11/2','subtract Integer PMC inplace')
329 .sub test_add_rats_inplace
339 is($P1,4,'adding rationals inplace')
340 is($P2,4,'adding rationals inplace')
343 .sub test_add_int_pmc_inplace
353 is($P2,'17/2','add Integer PMCs inplace')
354 is($P3,'17/2','add Integer PMCs inplace')
357 .sub test_add_float_pmc_inplace
367 is($P2,'17/2','add Float PMCs inplace')
368 is($P3,'17/2','add Float PMCs inplace')
371 .sub test_add_int_inplace
380 is($P1,'31/2','add integers inplace')
381 is($P2,'17/2','add integers inplace')
384 .sub test_add_float_inplace
393 is($P1,'31/2','add floats inplace')
394 is($P2,'17/2','add floats inplace')
400 ok($P1,'initialization')
405 $S1 = $P1.'version'()
406 ok($S1,'can get version number')
409 .sub test_set_get_native_int
415 is($I2,42,'set and get native int')
418 .sub test_set_get_int
426 is($P3,7,'set and get int')
429 .sub test_set_get_float
438 is($P3,7.11,'set and set float',0.0001)
446 is($P1,'11/4','increment a rational')
449 is($P1,'3/4','decrement a rational')
452 .sub test_set_get_string
460 is($P3,"7/4",'set and get string')
463 .sub test_set_get_native_float
469 is($N1,11.1,'set and get a native float')
472 .sub test_set_get_native_string
478 is($S2,'7/4','set and get native string')
485 # vim: expandtab shiftwidth=4 ft=pir: