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 loadlib $P1, 'rational'
23 .local pmc config_hash, interp
27 config_hash = interp[.IGLOBALS_CONFIG_HASH]
28 $S0 = config_hash['gmp']
33 # The following tests only run if GMP is installed
35 test_set_get_native_int()
36 test_set_get_native_float()
37 test_set_get_native_string()
44 test_add_int_inplace()
45 test_add_float_inplace()
47 test_add_int_pmc_inplace()
48 test_add_float_pmc_inplace()
49 test_add_rats_inplace()
53 test_subtract_int_pmc()
58 test_multiply_int_pmc()
59 test_multiply_float_pmc()
65 test_divide_float_pmc()
105 if $P2 == $P3 goto EQ
108 ok(1,'== on Rational PMC')
111 ok(0,'== on Rational PMC')
117 is($I1,-1,'cmp on Rational PMC')
118 is($I2,1,'cmp on Rational PMC')
129 is($P1,'3/14','divide int')
130 is($P2,'3/14','divide int')
133 .sub test_divide_float
141 is($P1,'3/14','divide float')
142 is($P2,'3/14','divide float')
146 .sub test_divide_int_pmc
156 is($P2,'3/14','divide Integer PMC')
157 is($P3,'3/14','divide Integer PMC')
160 .sub test_divide_float_pmc
170 is($P2,'3/14','divide Float PMC')
171 is($P3,'3/14','divide Float PMC')
174 .sub test_divide_rats
184 is($P1,'3/5','divide Rational PMC')
185 is($P2,'3/5','divide Rational PMC')
188 .sub test_multiply_int
196 is($P1,'21/2','multiply int')
197 is($P2,'21/2','multiply int')
200 .sub test_multiply_float
208 is($P1,'21/2','multiply float')
209 is($P2,'21/2','multiply float')
212 .sub test_multiply_int_pmc
222 is($P2,'21/2','multiply Integer PMC')
223 is($P3,'21/2','multiply Integer PMC')
226 .sub test_multiply_float_pmc
236 is($P2,'21/2','multiply Float PMC')
237 is($P3,'21/2','multiply Float PMC')
241 .sub test_multiply_rats
251 is($P1,'15/4','multiply Rational PMC')
252 is($P2,'15/4','multiply Rational PMC')
255 .sub test_subtract_rats
265 is($P1,-1,'subtract Rational inplace')
266 is($P2,-1,'subtract Rational inplace')
270 .sub test_subtract_int
279 is($P1,'-25/2','subtract int inplace')
280 is($P2,'-11/2','subtract int inplace')
283 .sub test_subtract_float
292 is($P1,'-25/2','subtract float inplace')
293 is($P2,'-11/2','subtract float inplace')
296 .sub test_subtract_int_pmc
306 is($P2,'-11/2','subtract Integer PMC inplace')
307 is($P3,'-11/2','subtract Integer PMC inplace')
310 .sub test_add_rats_inplace
320 is($P1,4,'adding rationals inplace')
321 is($P2,4,'adding rationals inplace')
324 .sub test_add_int_pmc_inplace
334 is($P2,'17/2','add Integer PMCs inplace')
335 is($P3,'17/2','add Integer PMCs inplace')
338 .sub test_add_float_pmc_inplace
348 is($P2,'17/2','add Float PMCs inplace')
349 is($P3,'17/2','add Float PMCs inplace')
352 .sub test_add_int_inplace
361 is($P1,'31/2','add integers inplace')
362 is($P2,'17/2','add integers inplace')
365 .sub test_add_float_inplace
374 is($P1,'31/2','add floats inplace')
375 is($P2,'17/2','add floats inplace')
381 ok($P1,'initialization')
386 $S1 = $P1.'version'()
387 ok($S1,'can get version number')
390 .sub test_set_get_native_int
396 is($I2,42,'set and get native int')
399 .sub test_set_get_int
407 is($P3,7,'set and get int')
410 .sub test_set_get_float
419 is($P3,7.11,'set and set float',0.0001)
427 is($P1,'11/4','increment a rational')
430 is($P1,'3/4','decrement a rational')
433 .sub test_set_get_string
441 is($P3,"7/4",'set and get string')
444 .sub test_set_get_native_float
450 is($N1,11.1,'set and get a native float')
453 .sub test_set_get_native_string
459 is($S2,'7/4','set and get native string')
466 # vim: expandtab shiftwidth=4 ft=pir: