1#!perl 2 3use strict; 4use warnings; 5 6use Math::Matrix; 7use Test::More tests => 68; 8 9note('Math::Matrix -> randi(7);'); 10 11{ 12 my $x = Math::Matrix -> randi(7); 13 is(ref($x), 'Math::Matrix', '$x is a Math::Matrix'); 14 my ($nrow, $ncol) = $x -> size(); 15 cmp_ok($nrow, '==', 1, 'number of rows in $x'); 16 cmp_ok($ncol, '==', 1, 'number of columns in $x'); 17 for my $i (0 .. $nrow - 1) { 18 for my $j (0 .. $ncol - 1) { 19 ok(0 <= $x->[$i][$j] && $x->[$i][$j] <= 7, "0 <= \$x->[$i][$j] <= 7"); 20 } 21 } 22} 23 24note('Math::Matrix -> randi(7, 3);'); 25 26{ 27 my $x = Math::Matrix -> randi(7, 3); 28 is(ref($x), 'Math::Matrix', '$x is a Math::Matrix'); 29 my ($nrow, $ncol) = $x -> size(); 30 cmp_ok($nrow, '==', 3, 'number of rows in $x'); 31 cmp_ok($ncol, '==', 3, 'number of columns in $x'); 32 for my $i (0 .. $nrow - 1) { 33 for my $j (0 .. $ncol - 1) { 34 ok(0 <= $x->[$i][$j] && $x->[$i][$j] <= 7, "0 <= \$x->[$i][$j] <= 7"); 35 } 36 } 37} 38 39note('Math::Matrix -> randi(7, 3, 5);'); 40 41{ 42 my $x = Math::Matrix -> randi(7, 3, 5); 43 is(ref($x), 'Math::Matrix', '$x is a Math::Matrix'); 44 my ($nrow, $ncol) = $x -> size(); 45 cmp_ok($nrow, '==', 3, 'number of rows in $x'); 46 cmp_ok($ncol, '==', 5, 'number of columns in $x'); 47 for my $i (0 .. $nrow - 1) { 48 for my $j (0 .. $ncol - 1) { 49 ok(0 <= $x->[$i][$j] && $x->[$i][$j] <= 7, "0 <= \$x->[$i][$j] <= 7"); 50 } 51 } 52} 53 54note('Math::Matrix -> randi([-4, 7]);'); 55 56{ 57 my $x = Math::Matrix -> randi([-4, 7]); 58 is(ref($x), 'Math::Matrix', '$x is a Math::Matrix'); 59 my ($nrow, $ncol) = $x -> size(); 60 cmp_ok($nrow, '==', 1, 'number of rows in $x'); 61 cmp_ok($ncol, '==', 1, 'number of columns in $x'); 62 for my $i (0 .. $nrow - 1) { 63 for my $j (0 .. $ncol - 1) { 64 ok(-4 <= $x->[$i][$j] && $x->[$i][$j] <= 7, "-4 <= \$x->[$i][$j] <= 7"); 65 } 66 } 67} 68 69note('Math::Matrix -> randi([-4, 7], 3);'); 70 71{ 72 my $x = Math::Matrix -> randi([-4, 7], 3); 73 is(ref($x), 'Math::Matrix', '$x is a Math::Matrix'); 74 my ($nrow, $ncol) = $x -> size(); 75 cmp_ok($nrow, '==', 3, 'number of rows in $x'); 76 cmp_ok($ncol, '==', 3, 'number of columns in $x'); 77 for my $i (0 .. $nrow - 1) { 78 for my $j (0 .. $ncol - 1) { 79 ok(-4 <= $x->[$i][$j] && $x->[$i][$j] <= 7, "-4 <= \$x->[$i][$j] <= 7"); 80 } 81 } 82} 83 84note('Math::Matrix -> randi([-4, 7], 3, 5);'); 85 86{ 87 my $x = Math::Matrix -> randi([-4, 7], 3, 5); 88 is(ref($x), 'Math::Matrix', '$x is a Math::Matrix'); 89 my ($nrow, $ncol) = $x -> size(); 90 cmp_ok($nrow, '==', 3, 'number of rows in $x'); 91 cmp_ok($ncol, '==', 5, 'number of columns in $x'); 92 for my $i (0 .. $nrow - 1) { 93 for my $j (0 .. $ncol - 1) { 94 ok(-4 <= $x->[$i][$j] && $x->[$i][$j] <= 7, "-4 <= \$x->[$i][$j] <= 7"); 95 } 96 } 97} 98