[svn:parrot] r42567 - trunk/t/library

fperrad at svn.parrot.org fperrad at svn.parrot.org
Wed Nov 18 19:27:11 UTC 2009


Author: fperrad
Date: Wed Nov 18 19:27:08 2009
New Revision: 42567
URL: https://trac.parrot.org/parrot/changeset/42567

Log:
[mt19937] convert test in PIR (from http://github.com/fperrad/parrot-MT19937)

Modified:
   trunk/t/library/mt19937ar.t

Modified: trunk/t/library/mt19937ar.t
==============================================================================
--- trunk/t/library/mt19937ar.t	Wed Nov 18 08:53:49 2009	(r42566)
+++ trunk/t/library/mt19937ar.t	Wed Nov 18 19:27:08 2009	(r42567)
@@ -1,153 +1,62 @@
-#!perl
-# Copyright (C) 2008, Parrot Foundation.
+#!parrot
+# Copyright (C) 2009, Parrot Foundation.
 # $Id$
 
-use strict;
-use warnings;
-use lib qw( t . lib ../lib ../../lib );
-use Test::More;
-use Parrot::Test tests => 10;
-
 =head1 NAME
 
 t/library/mt19937ar.t - Math::Random::MT tests
 
 =head1 SYNOPSIS
 
-    % prove t/library/mt19937ar.t
+    % parrot t/library/mt19937ar.t
 
 =cut
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT typeof' );
-.sub test :main
+.sub 'main' :main
     load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
-    $S0 = typeof mt
-    print $S0
-    print "\n"
-.end
-CODE
-Math;Random;MT
-OUTPUT
 
+    .include 'test_more.pir'
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can init_genrand' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
-    $I0 = can mt, 'init_genrand'
-    print $I0
-    print "\n"
-.end
-CODE
-1
-OUTPUT
+    plan(10)
 
+    test_interfaces()
+    test_output()
+.end
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can init_by_array' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
+.sub 'test_interfaces'
     .local pmc mt
     mt = new [ 'Math'; 'Random'; 'MT' ]
-    $I0 = can mt, 'init_by_array'
-    print $I0
-    print "\n"
-.end
-CODE
-1
-OUTPUT
 
+    $S0 = typeof mt
+    is($S0, 'Math;Random;MT', "MT typeof")
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can genrand_int32' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
-    $I0 = can mt, 'genrand_int32'
-    print $I0
-    print "\n"
-.end
-CODE
-1
-OUTPUT
+    $I0 = can mt, 'init_genrand'
+    ok($I0, "MT can init_genrand")
 
+    $I0 = can mt, 'init_by_array'
+    ok($I0, "MT can init_by_array")
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can genrand_int31' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
-    $I0 = can mt, 'genrand_int31'
-    print $I0
-    print "\n"
-.end
-CODE
-1
-OUTPUT
+    $I0 = can mt, 'genrand_int32'
+    ok($I0, "MT can genrand_int32")
 
+    $I0 = can mt, 'genrand_int31'
+    ok($I0, "MT can genrand_int31")
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can genrand_real1' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
     $I0 = can mt, 'genrand_real1'
-    print $I0
-    print "\n"
-.end
-CODE
-1
-OUTPUT
+    ok($I0, "MT can genrand_real1")
 
-
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can genrand_real2' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
     $I0 = can mt, 'genrand_real2'
-    print $I0
-    print "\n"
-.end
-CODE
-1
-OUTPUT
-
+    ok($I0, "MT can genrand_real2")
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can genrand_real3' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
     $I0 = can mt, 'genrand_real3'
-    print $I0
-    print "\n"
-.end
-CODE
-1
-OUTPUT
-
+    ok($I0, "MT can genrand_real3")
 
-pir_output_is( << 'CODE', << 'OUTPUT', 'MT can genrand_res53' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
-    .local pmc mt
-    mt = new [ 'Math'; 'Random'; 'MT' ]
     $I0 = can mt, 'genrand_res53'
-    print $I0
-    print "\n"
+    ok($I0, "MT can genrand_res53")
 .end
-CODE
-1
-OUTPUT
-
 
-my $out = Parrot::Test::slurp_file(File::Spec->catfile( 't', 'library', 'mt19937ar.txt' ));
-pir_output_is( << 'CODE', $out, 'mt19937ar output' );
-.sub test :main
-    load_bytecode 'Math/Random/mt19937ar.pbc'
+.sub 'generate_output' :anon
+    .param pmc fh
     .local pmc mt
     mt = new [ 'Math'; 'Random'; 'MT' ]
     .local pmc init
@@ -158,7 +67,7 @@
     set init[2], 0x345
     set init[3], 0x456
     mt.'init_by_array'(init)
-    print "1000 outputs of genrand_int32()\n"
+    fh.'puts'( "1000 outputs of genrand_int32()\n" )
     .local int i
     i = 0
     new $P0, 'FixedPMCArray'
@@ -168,36 +77,49 @@
     $I0 = mt.'genrand_int32'()
     $P0[0] = $I0
     $S0 = sprintf "%10lu ", $P0
-    print $S0
+    fh.'puts'( $S0 )
     $I0 = i % 5
     unless $I0 == 4 goto L3
-    print "\n"
+    fh.'puts'( "\n" )
   L3:
     inc i
     goto L1
   L2:
-    print "\n1000 outputs of genrand_real2()\n"
+    fh.'puts'( "\n1000 outputs of genrand_real2()\n" )
     i = 0
   L4:
     unless i < 1000 goto L5
     $N0 = mt.'genrand_real2'()
     $P0[0] = $N0
     $S0 = sprintf "%10.8f ", $P0
-    print $S0
+    fh.'puts'( $S0 )
     $I0 = i % 5
     unless $I0 == 4 goto L6
-    print "\n"
+    fh.'puts'( "\n" )
   L6:
     inc i
     goto L4
   L5:
 .end
-CODE
+
+.sub 'test_output'
+    .local pmc fh
+    fh = new 'FileHandle'
+    .local string ref
+    ref = fh.'readall'('t/library/mt19937ar.txt')
+    $P0 = split "\r\n", ref     # hack for Windows
+    ref = join "\n", $P0
+    fh = new 'StringHandle'
+    fh.'open'('output', 'w')
+    generate_output(fh)
+    $S0 = fh.'readall'()
+    fh.'close'()
+    is($S0, ref, "mt19937ar output")
+.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