1#!perl 2 3use strict; 4use warnings; 5 6use Math::Matrix; 7use Test::More tests => 5; 8 9{ 10 my $x = Math::Matrix -> new([[1, 3, 5, 7], 11 [2, 4, 6, 8]]); 12 my $y = $x -> to_col(); 13 14 is(ref($y), 'Math::Matrix', '$y is a Math::Matrix'); 15 is_deeply([ @$y ], [[1], [2], [3], [4], [5], [6], [7], [8]], 16 '$y has the right values'); 17 18 # Verify that modifying $y does not modify $x. 19 20 my ($nrowy, $ncoly) = $y -> size(); 21 for my $i (0 .. $nrowy - 1) { 22 for my $j (0 .. $ncoly - 1) { 23 $y -> [$i][$j] += 100; 24 } 25 } 26 27 is_deeply([ @$x ], [[1, 3, 5, 7], 28 [2, 4, 6, 8]], '$x is unmodified'); 29} 30 31{ 32 my $x = Math::Matrix -> new([]); 33 my $y = $x -> to_col(); 34 35 is(ref($y), 'Math::Matrix', '$y is a Math::Matrix'); 36 is_deeply([ @$y ], [], 37 '$y has the right values'); 38} 39