1# Tests for overloading 2 3use strict; 4use warnings; 5 6$| = 1; 7 8use Test::More 'tests' => 16; 9use Config; 10 11my @WARN; 12BEGIN { 13 # Warning signal handler 14 $SIG{__WARN__} = sub { push(@WARN, @_); }; 15} 16use_ok('Math::Random::MT::Auto', ':!auto'); 17use_ok('Math::Random::MT::Auto::Range'); 18 19# Set predetermined seed for verification test 20my @seed = ($Config{'uvsize'} == 8) 21 ? (0x12345, 0x23456, 0x34567, 0x45678) 22 : (0x123, 0x234, 0x345, 0x456); 23 24my @rand = ($Config{'uvsize'} == 8) ? 25 ( # 64-bit randoms 26 7266447313870364031, 4946485549665804864, 16945909448695747420, 16394063075524226720, 27 4873882236456199058, 14877448043947020171, 6740343660852211943, 13857871200353263164 28 ) : 29 ( # 32-bit randoms 30 1067595299, 955945823, 477289528, 4107218783, 31 4228976476, 3344332714, 3355579695, 227628506 32 ); 33 34# Create PRNG object 35my $prng; 36eval { $prng = Math::Random::MT::Auto->new('SEED' => \@seed); }; 37if (my $e = OIO->caught()) { 38 fail('MRMA->new(): ' . $e->error()); 39} elsif ($@) { 40 fail('MRMA->new(): ' . $@); 41} else { 42 pass('MRMA->new()'); 43} 44 45is("$prng", $rand[0] => ':Stringify'); 46SKIP: { 47 my $rnd = 0+$prng; 48 skip('64-bit overload bug', 1) 49 if (($] < 5.010) && ($Config{'uvsize'} == 8)); 50 is($rnd, $rand[1] => ':Numerify'); 51} 52is(($prng) ? 'odd' : 'even', 53 ($rand[2] & 1) ? 'odd' : 'even', => ':Boolify'); 54 55my $x = \&{$prng}; 56is($x->(), $rand[3] => ':Codify'); 57 58my @x = @{$prng}; 59is($x[0], $rand[4] => ':Arrayify'); 60 61@x = @{$prng->array(3)}; 62my @results = @rand[5..7]; 63is_deeply(\@x, \@results => '->array()'); 64 65### MRMA::Range 66 67my ($LO, $HI) = (1000, 9999); 68sub range 69{ 70 return (($_[0] % (($HI + 1) - $LO)) + $LO); 71} 72 73my $rand; 74eval { $rand = Math::Random::MT::Auto::Range->new('SEED' => \@seed, 75 'LOW' => $LO, 76 'HIGH' => $HI, 77 'TYPE' => 'INTEGER'); }; 78if (my $e = OIO->caught()) { 79 fail('MRMAR->new(): ' . $e->error()); 80} elsif ($@) { 81 fail('MRMAR->new(): ' . $@); 82} else { 83 pass('MRMAR->new()'); 84} 85 86is("$rand", range($rand[0]) => ':Stringify'); 87is(0+$rand, range($rand[1]) => ':Numerify'); 88is(($rand) ? 'odd' : 'even', 89 (range($rand[2]) & 1) ? 'odd' : 'even', => ':Boolify'); 90 91my $x = \&{$rand}; 92is($x->(), range($rand[3]) => ':Codify'); 93 94my @x = @{$rand}; 95is($x[0], range($rand[4]) => ':Arrayify'); 96 97@x = @{$rand->array(3)}; 98my @results = map { range($_) } @rand[5..7]; 99is_deeply(\@x, \@results => '->array()'); 100 101exit(0); 102 103# EOF 104