From 49aa40d9a16d94c84c54308ccd8a7356e0aa177b Mon Sep 17 00:00:00 2001 From: dukeleto Date: Thu, 18 Mar 2010 06:43:20 +0000 Subject: [PATCH] [t] Convert t/dynpmc/rational.t to PIR git-svn-id: https://svn.parrot.org/parrot/trunk@44995 d31e2699-5ff4-0310-a27c-f18f2fbe73fe --- t/dynpmc/rational.t | 1133 +++++++++++++++++++++------------------------------ 1 file changed, 466 insertions(+), 667 deletions(-) rewrite t/dynpmc/rational.t (61%) diff --git a/t/dynpmc/rational.t b/t/dynpmc/rational.t dissimilarity index 61% index 55fca0bfdf..b92bf6147d 100644 --- a/t/dynpmc/rational.t +++ b/t/dynpmc/rational.t @@ -1,667 +1,466 @@ -#! perl -# Copyright (C) 2008-2010, Parrot Foundation. -# $Id$ - -use strict; -use warnings; -use lib qw( . lib ../lib ../../lib ); - -use Test::More; -use Parrot::Test; -use Parrot::Config; - -=head1 NAME - -t/dynpmc/rational.t - Rational PMC - -=head1 SYNOPSIS - - % prove t/dynpmc/rational.t - -=head1 DESCRIPTION - -Tests the Rational PMC. - -=cut - -if ( $PConfig{gmp} ) { # If GMP is available, we check all functions. - plan tests => 32; -} -else { # If GMP is not available, we only test the constructor and the - plan tests => 2; # version-method that is used to detect presence of GMP at runtime. -} - -pir_output_is(<<'CODE', <<'OUTPUT', "Initialization"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - say "ok" - .end -CODE -ok -OUTPUT - -if (! $PConfig{gmp}) { # If GMP is not available, this is the last test: -pir_output_is(<<'CODE', <<'OUTPUT', "version-method"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - $S1 = $P1.'version'() - say $S1 - .end -CODE -0.0.0 -OUTPUT -exit; -} - -# These tests are only run, if GMP is available. -pir_output_is(<<'CODE', <<'OUTPUT', "version-method"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - $S1 = $P1.'version'() - say "ok" - .end -CODE -ok -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Set and get native integer"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - - $I1 = 42 - $P1 = $I1 - $I2 = $P1 - - say $I2 - .end -CODE -42 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Set and get native float"); - .sub main :main - loadlib $P0, 'rational' - new $P0, 'Rational' - - $N0 = 11.1 - $P0 = $N0 - $N1 = $P0 - - say $N1 - .end -CODE -11.1 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Set and get native string"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - - $S1 = "7/4" - $P1 = $S1 - $S2 = $P1 - - say $S2 - .end -CODE -7/4 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Set and get Integer"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - - new $P2, 'Integer' - new $P3, 'Integer' - - $P2 = 7 - $P1 = $P2 - $P3 = $P1 - - say $P3 - .end -CODE -7 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Set and get Float"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - - new $P2, 'Float' - new $P3, 'Float' - - $P2 = 7.110000 - $P1 = $P2 - $P3 = $P1 - - say $P3 - .end -CODE -7.11 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Set and get String"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - - new $P2, 'String' - new $P3, 'String' - - $P2 = "7/4" - $P1 = $P2 - $P3 = $P1 - - say $P3 - .end -CODE -7/4 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Increment and decrement"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - - $P1 = "7/4" - inc $P1 - print $P1 - print "\n" - - dec $P1 - dec $P1 - say $P1 - .end -CODE -11/4 -3/4 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Adding integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $I1 = 7 - - $P1 = "3/2" - $P2 = $P1 + $I1 - $P1 = $P1 + $I1 - $P1 = $P1 + $I1 - - say $P1 - say $P2 - .end -CODE -31/2 -17/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Adding floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $N1 = 7. - - $P1 = "3/2" - $P2 = $P1 + $N1 - $P1 = $P1 + $N1 - $P1 = $P1 + $N1 - - say $P1 - say $P2 - .end -CODE -31/2 -17/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Adding Integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Integer' - - $P4 = 7 - - $P2 = "3/2" - $P3 = $P2 + $P4 - $P2 = $P2 + $P4 - - say $P2 - say $P3 - .end -CODE -17/2 -17/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Adding Floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Float' - - $P4 = 7. - - $P2 = "3/2" - $P3 = $P2 + $P4 - $P2 = $P2 + $P4 - - say $P2 - say $P3 - .end -CODE -17/2 -17/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Adding Rationals (+inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - new $P3, 'Rational' - - $P2 = "3/2" - $P3 = "5/2" - - $P1 = $P2 + $P3 - $P2 = $P2 + $P3 - - say $P1 - say $P2 - .end -CODE -4 -4 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $I1 = 7 - - $P1 = "3/2" - $P2 = $P1 - $I1 - $P1 = $P1 - $I1 - $P1 = $P1 - $I1 - - say $P1 - say $P2 - .end -CODE --25/2 --11/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $N1 = 7. - - $P1 = "3/2" - $P2 = $P1 - $N1 - $P1 = $P1 - $N1 - $P1 = $P1 - $N1 - - say $P1 - say $P2 - .end -CODE --25/2 --11/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting Integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Integer' - - $P4 = 7 - - $P2 = "3/2" - $P3 = $P2 - $P4 - $P2 = $P2 - $P4 - - say $P2 - say $P3 - .end -CODE --11/2 --11/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting Floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Float' - - $P4 = 7. - - $P2 = "3/2" - $P3 = $P2 - $P4 - $P2 = $P2 - $P4 - - say $P2 - say $P3 - .end -CODE --11/2 --11/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting Rationals (+inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - new $P3, 'Rational' - - $P2 = "3/2" - $P3 = "5/2" - - $P1 = $P2 - $P3 - $P2 = $P2 - $P3 - - say $P1 - say $P2 - .end -CODE --1 --1 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $I1 = 7 - - $P1 = "3/2" - $P2 = $P1 * $I1 - $P1 = $P1 * $I1 - - say $P1 - say $P2 - .end -CODE -21/2 -21/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $N1 = 7. - - $P1 = "3/2" - $P2 = $P1 * $N1 - $P1 = $P1 * $N1 - - say $P1 - say $P2 - .end -CODE -21/2 -21/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying Integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Integer' - - $P4 = 7 - - $P2 = "3/2" - $P3 = $P2 * $P4 - $P2 = $P2 * $P4 - - say $P2 - say $P3 - .end -CODE -21/2 -21/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying Floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Float' - - $P4 = 7. - - $P2 = "3/2" - $P3 = $P2 * $P4 - $P2 = $P2 * $P4 - - say $P2 - say $P3 - .end -CODE -21/2 -21/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying Rationals (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - new $P3, 'Rational' - - $P2 = "3/2" - $P3 = "5/2" - - $P1 = $P2 * $P3 - $P2 = $P2 * $P3 - - say $P1 - say $P2 - .end -CODE -15/4 -15/4 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Dividing integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $I1 = 7 - - $P1 = "3/2" - $P2 = $P1 / $I1 - $P1 = $P1 / $I1 - - say $P1 - say $P2 - .end -CODE -3/14 -3/14 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Dividing floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - $N1 = 7. - - $P1 = "3/2" - $P2 = $P1 / $N1 - $P1 = $P1 / $N1 - - say $P1 - say $P2 - .end -CODE -3/14 -3/14 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Dividing Integers (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Integer' - - $P4 = 7 - - $P2 = "3/2" - $P3 = $P2 / $P4 - $P2 = $P2 / $P4 - - say $P2 - say $P3 - .end -CODE -3/14 -3/14 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Dividing Floats (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - new $P4, 'Float' - - $P4 = 7. - - $P2 = "3/2" - $P3 = $P2 / $P4 - $P2 = $P2 / $P4 - - say $P2 - say $P3 - .end -CODE -3/14 -3/14 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Dividing Rationals (+ inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P1, 'Rational' - new $P2, 'Rational' - new $P3, 'Rational' - - $P2 = "3/2" - $P3 = "5/2" - - $P1 = $P2 / $P3 - $P2 = $P2 / $P3 - - say $P1 - say $P2 - .end -CODE -3/5 -3/5 -OUTPUT -pir_output_is(<<'CODE', <<'OUTPUT', "Negating (+inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - - $P2 = "-3/2" - $P3 = -$P2 - $P2 = -$P2 - - say $P2 - say $P3 - .end -CODE -3/2 -3/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Absolute value (+inplace operation)"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - - $P2 = "-3/2" - $P3 = abs $P2 - abs $P2 - - say $P2 - say $P3 - .end -CODE -3/2 -3/2 -OUTPUT - -pir_output_is(<<'CODE', <<'OUTPUT', "Comparing rationals to rationals"); - .sub main :main - loadlib $P1, 'rational' - new $P2, 'Rational' - new $P3, 'Rational' - - $P2 = "3/2" - $P3 = "6/4" - - if $P2 == $P3 goto EQ - goto NE - EQ: - say "1" - goto END_EQ - NE: - say "0" - END_EQ: - - $P3 = "7/4" - cmp $I1, $P2, $P3 - cmp $I2, $P3, $P2 - - say $I1 - say $I2 - .end -CODE -1 --1 -1 -OUTPUT - -# Local Variables: -# mode: cperl -# cperl-indent-level: 4 -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4: +#! parrot +# Copyright (C) 2008-2010, Parrot Foundation. +# $Id$ + +=head1 NAME + +t/dynpmc/rational.t - Rational PMC + +=head1 SYNOPSIS + + % prove t/dynpmc/rational.t + +=head1 DESCRIPTION + +Tests the Rational PMC. + +=cut + +.sub main :main + .include 'test_more.pir' + .include 'iglobals.pasm' + loadlib $P1, 'rational' + .local pmc config_hash, interp + + plan(55) + interp = getinterp + config_hash = interp[.IGLOBALS_CONFIG_HASH] + $S0 = config_hash['gmp'] + + test_init() + test_version() + + # The following tests only run if GMP is installed + unless $S0 goto done + test_set_get_native_int() + test_set_get_native_float() + test_set_get_native_string() + + test_set_get_int() + test_set_get_float() + test_set_get_string() + + test_inc_dec() + test_add_int_inplace() + test_add_float_inplace() + + test_add_int_pmc_inplace() + test_add_float_pmc_inplace() + test_add_rats_inplace() + + test_subtract_int() + test_subtract_float() + test_subtract_int_pmc() + test_subtract_rats() + + test_multiply_int() + test_multiply_float() + test_multiply_int_pmc() + test_multiply_float_pmc() + test_multiply_rats() + + test_divide_int() + test_divide_float() + test_divide_int_pmc() + test_divide_float_pmc() + test_divide_rats() + + test_neg() + test_abs() + test_cmp() + done: + .return() +.end + +.sub test_neg + new $P2, 'Rational' + new $P3, 'Rational' + + $P2 = "-3/2" + $P3 = -$P2 + $P2 = -$P2 + + is($P2,'3/2','neg') + is($P3,'3/2','neg') +.end + +.sub test_abs + new $P2, 'Rational' + new $P3, 'Rational' + + $P2 = "-3/2" + $P3 = abs $P2 + abs $P2 + is($P2,'3/2','abs') + is($P3,'3/2','abs') +.end + +.sub test_cmp + new $P2, 'Rational' + new $P3, 'Rational' + + $P2 = "3/2" + $P3 = "6/4" + + if $P2 == $P3 goto EQ + goto NE + EQ: + ok(1,'== on Rational PMC') + goto END_EQ + NE: + ok(0,'== on Rational PMC') + END_EQ: + + $P3 = "7/4" + cmp $I1, $P2, $P3 + cmp $I2, $P3, $P2 + is($I1,-1,'cmp on Rational PMC') + is($I2,1,'cmp on Rational PMC') +.end + +.sub test_divide_int + new $P1, 'Rational' + new $P2, 'Rational' + $I1 = 7 + + $P1 = "3/2" + $P2 = $P1 / $I1 + $P1 = $P1 / $I1 + is($P1,'3/14','divide int') + is($P2,'3/14','divide int') +.end + +.sub test_divide_float + new $P1, 'Rational' + new $P2, 'Rational' + $N1 = 7. + + $P1 = "3/2" + $P2 = $P1 / $N1 + $P1 = $P1 / $N1 + is($P1,'3/14','divide float') + is($P2,'3/14','divide float') + +.end + +.sub test_divide_int_pmc + new $P2, 'Rational' + new $P3, 'Rational' + new $P4, 'Integer' + + $P4 = 7 + + $P2 = "3/2" + $P3 = $P2 / $P4 + $P2 = $P2 / $P4 + is($P2,'3/14','divide Integer PMC') + is($P3,'3/14','divide Integer PMC') +.end + +.sub test_divide_float_pmc + new $P2, 'Rational' + new $P3, 'Rational' + new $P4, 'Float' + + $P4 = 7. + + $P2 = "3/2" + $P3 = $P2 / $P4 + $P2 = $P2 / $P4 + is($P2,'3/14','divide Float PMC') + is($P3,'3/14','divide Float PMC') +.end + +.sub test_divide_rats + new $P1, 'Rational' + new $P2, 'Rational' + new $P3, 'Rational' + + $P2 = "3/2" + $P3 = "5/2" + + $P1 = $P2 / $P3 + $P2 = $P2 / $P3 + is($P1,'3/5','divide Rational PMC') + is($P2,'3/5','divide Rational PMC') +.end + +.sub test_multiply_int + new $P1, 'Rational' + new $P2, 'Rational' + $I1 = 7 + + $P1 = "3/2" + $P2 = $P1 * $I1 + $P1 = $P1 * $I1 + is($P1,'21/2','multiply int') + is($P2,'21/2','multiply int') +.end + +.sub test_multiply_float + new $P1, 'Rational' + new $P2, 'Rational' + $N1 = 7. + + $P1 = "3/2" + $P2 = $P1 * $N1 + $P1 = $P1 * $N1 + is($P1,'21/2','multiply float') + is($P2,'21/2','multiply float') +.end + +.sub test_multiply_int_pmc + new $P2, 'Rational' + new $P3, 'Rational' + new $P4, 'Integer' + + $P4 = 7 + + $P2 = "3/2" + $P3 = $P2 * $P4 + $P2 = $P2 * $P4 + is($P2,'21/2','multiply Integer PMC') + is($P3,'21/2','multiply Integer PMC') +.end + +.sub test_multiply_float_pmc + new $P2, 'Rational' + new $P3, 'Rational' + new $P4, 'Float' + + $P4 = 7. + + $P2 = "3/2" + $P3 = $P2 * $P4 + $P2 = $P2 * $P4 + is($P2,'21/2','multiply Float PMC') + is($P3,'21/2','multiply Float PMC') + +.end + +.sub test_multiply_rats + new $P1, 'Rational' + new $P2, 'Rational' + new $P3, 'Rational' + + $P2 = "3/2" + $P3 = "5/2" + + $P1 = $P2 * $P3 + $P2 = $P2 * $P3 + is($P1,'15/4','multiply Rational PMC') + is($P2,'15/4','multiply Rational PMC') +.end + +.sub test_subtract_rats + new $P1, 'Rational' + new $P2, 'Rational' + new $P3, 'Rational' + + $P2 = "3/2" + $P3 = "5/2" + + $P1 = $P2 - $P3 + $P2 = $P2 - $P3 + is($P1,-1,'subtract Rational inplace') + is($P2,-1,'subtract Rational inplace') + +.end + +.sub test_subtract_int + new $P1, 'Rational' + new $P2, 'Rational' + $I1 = 7 + + $P1 = "3/2" + $P2 = $P1 - $I1 + $P1 = $P1 - $I1 + $P1 = $P1 - $I1 + is($P1,'-25/2','subtract int inplace') + is($P2,'-11/2','subtract int inplace') +.end + +.sub test_subtract_float + new $P1, 'Rational' + new $P2, 'Rational' + $N1 = 7. + + $P1 = "3/2" + $P2 = $P1 - $N1 + $P1 = $P1 - $N1 + $P1 = $P1 - $N1 + is($P1,'-25/2','subtract float inplace') + is($P2,'-11/2','subtract float inplace') +.end + +.sub test_subtract_int_pmc + new $P2, 'Rational' + new $P3, 'Rational' + new $P4, 'Integer' + + $P4 = 7 + + $P2 = "3/2" + $P3 = $P2 - $P4 + $P2 = $P2 - $P4 + is($P2,'-11/2','subtract Integer PMC inplace') + is($P3,'-11/2','subtract Integer PMC inplace') +.end + +.sub test_add_rats_inplace + new $P1, 'Rational' + new $P2, 'Rational' + new $P3, 'Rational' + + $P2 = "3/2" + $P3 = "5/2" + + $P1 = $P2 + $P3 + $P2 = $P2 + $P3 + is($P1,4,'adding rationals inplace') + is($P2,4,'adding rationals inplace') +.end + +.sub test_add_int_pmc_inplace + new $P2, 'Rational' + new $P3, 'Rational' + new $P4, 'Integer' + + $P4 = 7 + + $P2 = "3/2" + $P3 = $P2 + $P4 + $P2 = $P2 + $P4 + is($P2,'17/2','add Integer PMCs inplace') + is($P3,'17/2','add Integer PMCs inplace') +.end + +.sub test_add_float_pmc_inplace + new $P2, 'Rational' + new $P3, 'Rational' + new $P4, 'Float' + + $P4 = 7. + + $P2 = "3/2" + $P3 = $P2 + $P4 + $P2 = $P2 + $P4 + is($P2,'17/2','add Float PMCs inplace') + is($P3,'17/2','add Float PMCs inplace') +.end + +.sub test_add_int_inplace + new $P1, 'Rational' + new $P2, 'Rational' + $I1 = 7 + + $P1 = "3/2" + $P2 = $P1 + $I1 + $P1 = $P1 + $I1 + $P1 = $P1 + $I1 + is($P1,'31/2','add integers inplace') + is($P2,'17/2','add integers inplace') +.end + +.sub test_add_float_inplace + new $P1, 'Rational' + new $P2, 'Rational' + $N1 = 7. + + $P1 = "3/2" + $P2 = $P1 + $N1 + $P1 = $P1 + $N1 + $P1 = $P1 + $N1 + is($P1,'31/2','add floats inplace') + is($P2,'17/2','add floats inplace') +.end + + +.sub test_init + new $P1, 'Rational' + ok($P1,'initialization') +.end + +.sub test_version + new $P1, 'Rational' + $S1 = $P1.'version'() + ok($S1,'can get version number') +.end + +.sub test_set_get_native_int + new $P1, 'Rational' + + $I1 = 42 + $P1 = $I1 + $I2 = $P1 + is($I2,42,'set and get native int') +.end + +.sub test_set_get_int + new $P1, 'Rational' + new $P2, 'Integer' + new $P3, 'Integer' + + $P2 = 7 + $P1 = $P2 + $P3 = $P1 + is($P3,7,'set and get int') +.end + +.sub test_set_get_float + new $P1, 'Rational' + + new $P2, 'Float' + new $P3, 'Float' + + $P2 = 7.110000 + $P1 = $P2 + $P3 = $P1 + is($P3,7.11,'set and set float',0.0001) +.end + +.sub test_inc_dec + new $P1, 'Rational' + + $P1 = "7/4" + inc $P1 + is($P1,'11/4','increment a rational') + dec $P1 + dec $P1 + is($P1,'3/4','decrement a rational') +.end + +.sub test_set_get_string + new $P1, 'Rational' + new $P2, 'String' + new $P3, 'String' + + $P2 = "7/4" + $P1 = $P2 + $P3 = $P1 + is($P3,"7/4",'set and get string') +.end + +.sub test_set_get_native_float + new $P0, 'Rational' + + $N0 = 11.1 + $P0 = $N0 + $N1 = $P0 + is($N1,11.1,'set and get a native float') +.end + +.sub test_set_get_native_string + new $P1, 'Rational' + + $S1 = "7/4" + $P1 = $S1 + $S2 = $P1 + is($S2,'7/4','set and get native string') +.end + +# Local Variables: +# mode: pir +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4 ft=pir: -- 2.11.4.GIT