[svn:parrot] r44995 - trunk/t/dynpmc

dukeleto at svn.parrot.org dukeleto at svn.parrot.org
Thu Mar 18 06:43:23 UTC 2010


Author: dukeleto
Date: Thu Mar 18 06:43:20 2010
New Revision: 44995
URL: https://trac.parrot.org/parrot/changeset/44995

Log:
[t] Convert t/dynpmc/rational.t to PIR

Modified:
   trunk/t/dynpmc/rational.t

Modified: trunk/t/dynpmc/rational.t
==============================================================================
--- trunk/t/dynpmc/rational.t	Thu Mar 18 05:22:27 2010	(r44994)
+++ trunk/t/dynpmc/rational.t	Thu Mar 18 06:43:20 2010	(r44995)
@@ -1,15 +1,7 @@
-#! perl
+#! parrot
 # 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
@@ -24,210 +16,134 @@
 
 =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'
+.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
 
-    $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
+.sub test_neg
+    new $P2, 'Rational'
+    new $P3, 'Rational'
 
-    say $P3
-  .end
-CODE
-7.11
-OUTPUT
+    $P2 = "-3/2"
+    $P3 = -$P2
+    $P2 = -$P2
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Set and get String");
-  .sub main :main
-    loadlib $P1, 'rational'
-    new $P1, 'Rational'
+    is($P2,'3/2','neg')
+    is($P3,'3/2','neg')
+.end
 
-    new $P2, 'String'
-    new $P3, 'String'
+.sub test_abs
+    new $P2, 'Rational'
+    new $P3, 'Rational'
 
-    $P2 = "7/4"
-    $P1 = $P2
-    $P3 = $P1
+    $P2 = "-3/2"
+    $P3 = abs $P2
+    abs $P2
+    is($P2,'3/2','abs')
+    is($P3,'3/2','abs')
+.end
 
-    say $P3
-  .end
-CODE
-7/4
-OUTPUT
+.sub test_cmp
+    new $P2, 'Rational'
+    new $P3, 'Rational'
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Increment and decrement");
-  .sub main :main
-    loadlib $P1, 'rational'
-    new $P1, 'Rational'
+    $P2 = "3/2"
+    $P3 = "6/4"
 
-    $P1 = "7/4"
-    inc $P1
-    print $P1
-    print "\n"
+    if $P2 == $P3 goto EQ
+    goto NE
+  EQ:
+    ok(1,'== on Rational PMC')
+    goto END_EQ
+  NE:
+    ok(0,'== on Rational PMC')
+  END_EQ:
 
-    dec $P1
-    dec $P1
-    say $P1
-  .end
-CODE
-11/4
-3/4
-OUTPUT
+    $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
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Adding integers (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_divide_int
     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
+    $P2 = $P1 / $I1
+    $P1 = $P1 / $I1
+    is($P1,'3/14','divide int')
+    is($P2,'3/14','divide int')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Adding floats (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_divide_float
     new $P1, 'Rational'
     new $P2, 'Rational'
     $N1 = 7.
 
     $P1 = "3/2"
-    $P2 = $P1 + $N1
-    $P1 = $P1 + $N1
-    $P1 = $P1 + $N1
+    $P2 = $P1 / $N1
+    $P1 = $P1 / $N1
+    is($P1,'3/14','divide float')
+    is($P2,'3/14','divide float')
 
-    say $P1
-    say $P2
-  .end
-CODE
-31/2
-17/2
-OUTPUT
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Adding Integers (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_divide_int_pmc
     new $P2, 'Rational'
     new $P3, 'Rational'
     new $P4, 'Integer'
@@ -235,20 +151,13 @@
     $P4 = 7
 
     $P2 = "3/2"
-    $P3 = $P2 + $P4
-    $P2 = $P2 + $P4
-
-    say $P2
-    say $P3
-  .end
-CODE
-17/2
-17/2
-OUTPUT
+    $P3 = $P2 / $P4
+    $P2 = $P2 / $P4
+    is($P2,'3/14','divide Integer PMC')
+    is($P3,'3/14','divide Integer PMC')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Adding Floats (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_divide_float_pmc
     new $P2, 'Rational'
     new $P3, 'Rational'
     new $P4, 'Float'
@@ -256,20 +165,13 @@
     $P4 = 7.
 
     $P2 = "3/2"
-    $P3 = $P2 + $P4
-    $P2 = $P2 + $P4
-
-    say $P2
-    say $P3
-  .end
-CODE
-17/2
-17/2
-OUTPUT
+    $P3 = $P2 / $P4
+    $P2 = $P2 / $P4
+    is($P2,'3/14','divide Float PMC')
+    is($P3,'3/14','divide Float PMC')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Adding Rationals (+inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_divide_rats
     new $P1, 'Rational'
     new $P2, 'Rational'
     new $P3, 'Rational'
@@ -277,60 +179,37 @@
     $P2 = "3/2"
     $P3 = "5/2"
 
-    $P1 = $P2 + $P3
-    $P2 = $P2 + $P3
-
-    say $P1
-    say $P2
-  .end
-CODE
-4
-4
-OUTPUT
+    $P1 = $P2 / $P3
+    $P2 = $P2 / $P3
+    is($P1,'3/5','divide Rational PMC')
+    is($P2,'3/5','divide Rational PMC')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting integers (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_multiply_int
     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
+    $P2 = $P1 * $I1
+    $P1 = $P1 * $I1
+    is($P1,'21/2','multiply int')
+    is($P2,'21/2','multiply int')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting floats (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_multiply_float
     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
+    $P2 = $P1 * $N1
+    $P1 = $P1 * $N1
+    is($P1,'21/2','multiply float')
+    is($P2,'21/2','multiply float')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting Integers (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_multiply_int_pmc
     new $P2, 'Rational'
     new $P3, 'Rational'
     new $P4, 'Integer'
@@ -338,20 +217,13 @@
     $P4 = 7
 
     $P2 = "3/2"
-    $P3 = $P2 - $P4
-    $P2 = $P2 - $P4
-
-    say $P2
-    say $P3
-  .end
-CODE
--11/2
--11/2
-OUTPUT
+    $P3 = $P2 * $P4
+    $P2 = $P2 * $P4
+    is($P2,'21/2','multiply Integer PMC')
+    is($P3,'21/2','multiply Integer PMC')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting Floats (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_multiply_float_pmc
     new $P2, 'Rational'
     new $P3, 'Rational'
     new $P4, 'Float'
@@ -359,20 +231,28 @@
     $P4 = 7.
 
     $P2 = "3/2"
-    $P3 = $P2 - $P4
-    $P2 = $P2 - $P4
+    $P3 = $P2 * $P4
+    $P2 = $P2 * $P4
+    is($P2,'21/2','multiply Float PMC')
+    is($P3,'21/2','multiply Float PMC')
 
-    say $P2
-    say $P3
-  .end
-CODE
--11/2
--11/2
-OUTPUT
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Subtracting Rationals (+inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.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'
@@ -382,56 +262,38 @@
 
     $P1 = $P2 - $P3
     $P2 = $P2 - $P3
+    is($P1,-1,'subtract Rational inplace')
+    is($P2,-1,'subtract Rational inplace')
 
-    say $P1
-    say $P2
-  .end
-CODE
--1
--1
-OUTPUT
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying integers (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_subtract_int
     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
+    $P2 = $P1 - $I1
+    $P1 = $P1 - $I1
+    $P1 = $P1 - $I1
+    is($P1,'-25/2','subtract int inplace')
+    is($P2,'-11/2','subtract int inplace')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying floats (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_subtract_float
     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
+    $P2 = $P1 - $N1
+    $P1 = $P1 - $N1
+    $P1 = $P1 - $N1
+    is($P1,'-25/2','subtract float inplace')
+    is($P2,'-11/2','subtract float inplace')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying Integers (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_subtract_int_pmc
     new $P2, 'Rational'
     new $P3, 'Rational'
     new $P4, 'Integer'
@@ -439,229 +301,166 @@
     $P4 = 7
 
     $P2 = "3/2"
-    $P3 = $P2 * $P4
-    $P2 = $P2 * $P4
-
-    say $P2
-    say $P3
-  .end
-CODE
-21/2
-21/2
-OUTPUT
+    $P3 = $P2 - $P4
+    $P2 = $P2 - $P4
+    is($P2,'-11/2','subtract Integer PMC inplace')
+    is($P3,'-11/2','subtract Integer PMC inplace')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying Floats (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_add_rats_inplace
+    new $P1, 'Rational'
     new $P2, 'Rational'
     new $P3, 'Rational'
-    new $P4, 'Float'
-
-    $P4 = 7.
 
     $P2 = "3/2"
-    $P3 = $P2 * $P4
-    $P2 = $P2 * $P4
+    $P3 = "5/2"
 
-    say $P2
-    say $P3
-  .end
-CODE
-21/2
-21/2
-OUTPUT
+    $P1 = $P2 + $P3
+    $P2 = $P2 + $P3
+    is($P1,4,'adding rationals inplace')
+    is($P2,4,'adding rationals inplace')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Multiplying Rationals (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
-    new $P1, 'Rational'
+.sub test_add_int_pmc_inplace
     new $P2, 'Rational'
     new $P3, 'Rational'
+    new $P4, 'Integer'
+
+    $P4 = 7
 
     $P2 = "3/2"
-    $P3 = "5/2"
+    $P3 = $P2 + $P4
+    $P2 = $P2 + $P4
+    is($P2,'17/2','add Integer PMCs inplace')
+    is($P3,'17/2','add Integer PMCs inplace')
+.end
 
-    $P1 = $P2 * $P3
-    $P2 = $P2 * $P3
+.sub test_add_float_pmc_inplace
+    new $P2, 'Rational'
+    new $P3, 'Rational'
+    new $P4, 'Float'
 
-    say $P1
-    say $P2
-  .end
-CODE
-15/4
-15/4
-OUTPUT
+    $P4 = 7.
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Dividing integers (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+    $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
-
-    say $P1
-    say $P2
-  .end
-CODE
-3/14
-3/14
-OUTPUT
+    $P2 = $P1 + $I1
+    $P1 = $P1 + $I1
+    $P1 = $P1 + $I1
+    is($P1,'31/2','add integers inplace')
+    is($P2,'17/2','add integers inplace')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Dividing floats (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_add_float_inplace
     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
+    $P2 = $P1 + $N1
+    $P1 = $P1 + $N1
+    $P1 = $P1 + $N1
+    is($P1,'31/2','add floats inplace')
+    is($P2,'17/2','add floats inplace')
+.end
 
-    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'
+.sub test_init
+    new $P1, 'Rational'
+    ok($P1,'initialization')
+.end
 
-    $P4 = 7.
+.sub test_version
+    new $P1, 'Rational'
+    $S1 = $P1.'version'()
+    ok($S1,'can get version number')
+.end
 
-    $P2 = "3/2"
-    $P3 = $P2 / $P4
-    $P2 = $P2 / $P4
+.sub test_set_get_native_int
+    new $P1, 'Rational'
 
-    say $P2
-    say $P3
-  .end
-CODE
-3/14
-3/14
-OUTPUT
+    $I1 = 42
+    $P1 = $I1
+    $I2 = $P1
+    is($I2,42,'set and get native int')
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Dividing Rationals (+ inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
+.sub test_set_get_int
     new $P1, 'Rational'
-    new $P2, 'Rational'
-    new $P3, 'Rational'
-
-    $P2 = "3/2"
-    $P3 = "5/2"
+    new $P2, 'Integer'
+    new $P3, 'Integer'
 
-    $P1 = $P2 / $P3
-    $P2 = $P2 / $P3
+    $P2 = 7
+    $P1 = $P2
+    $P3 = $P1
+    is($P3,7,'set and get int')
+.end
 
-    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'
+.sub test_set_get_float
+    new $P1, 'Rational'
 
-    $P2 = "-3/2"
-    $P3 = -$P2
-    $P2 = -$P2
+    new $P2, 'Float'
+    new $P3, 'Float'
 
-    say $P2
-    say $P3
-  .end
-CODE
-3/2
-3/2
-OUTPUT
+    $P2 = 7.110000
+    $P1 = $P2
+    $P3 = $P1
+    is($P3,7.11,'set and set float',0.0001)
+.end
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Absolute value (+inplace operation)");
-  .sub main :main
-    loadlib $P1, 'rational'
-    new $P2, 'Rational'
-    new $P3, 'Rational'
+.sub test_inc_dec
+    new $P1, 'Rational'
 
-    $P2 = "-3/2"
-    $P3 = abs $P2
-    abs $P2
+    $P1 = "7/4"
+    inc $P1
+    is($P1,'11/4','increment a rational')
+    dec $P1
+    dec $P1
+    is($P1,'3/4','decrement a rational')
+.end
 
-    say $P2
-    say $P3
-  .end
-CODE
-3/2
-3/2
-OUTPUT
+.sub test_set_get_string
+    new $P1, 'Rational'
+    new $P2, 'String'
+    new $P3, 'String'
 
-pir_output_is(<<'CODE', <<'OUTPUT', "Comparing rationals to rationals");
-  .sub main :main
-    loadlib $P1, 'rational'
-    new $P2, 'Rational'
-    new $P3, 'Rational'
+    $P2 = "7/4"
+    $P1 = $P2
+    $P3 = $P1
+    is($P3,"7/4",'set and get string')
+.end
 
-    $P2 = "3/2"
-    $P3 = "6/4"
+.sub test_set_get_native_float
+    new $P0, 'Rational'
 
-    if $P2 == $P3 goto EQ
-    goto NE
-  EQ:
-    say "1"
-    goto END_EQ
-  NE:
-    say "0"
-  END_EQ:
+    $N0 = 11.1
+    $P0 = $N0
+    $N1 = $P0
+    is($N1,11.1,'set and get a native float')
+.end
 
-    $P3 = "7/4"
-    cmp $I1, $P2, $P3
-    cmp $I2, $P3, $P2
+.sub test_set_get_native_string
+    new $P1, 'Rational'
 
-    say $I1
-    say $I2
-  .end
-CODE
-1
--1
-1
-OUTPUT
+    $S1 = "7/4"
+    $P1 = $S1
+    $S2 = $P1
+    is($S2,'7/4','set and get native string')
+.end
 
 # Local Variables:
-#   mode: cperl
-#   cperl-indent-level: 4
+#   mode: pir
 #   fill-column: 100
 # End:
-# vim: expandtab shiftwidth=4:
+# vim: expandtab shiftwidth=4 ft=pir:


More information about the parrot-commits mailing list