1#!perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8# Ensure a recent version of Math::Complex. Math Complex didn't support any way
9# of cloning/copying Math::Complex objects before version 1.57.
10
11my $min_math_complex_ver = 1.57;
12eval "use Math::Complex $min_math_complex_ver";
13plan skip_all => "Math::Complex $min_math_complex_ver required" if $@;
14
15use lib 't/lib';
16use Math::Matrix::Complex;
17
18plan tests => 26;
19
20{
21    my $x = Math::Matrix::Complex -> new([[1, 2],
22                                          [4, 5]]);
23    my $y = Math::Matrix::Complex -> new([[3],
24                                          [6]]);
25    my $z = $x -> catcol($y);
26
27    is(ref($z), 'Math::Matrix::Complex', '$z is a Math::Matrix::Complex');
28    is_deeply([ @$z ], [[1, 2, 3],
29                        [4, 5, 6]], '$z has the right values');
30
31    is_deeply([ @$x ], [[1, 2],
32                        [4, 5]], '$x is unmodified');
33    is_deeply([ @$y ], [[3],
34                        [6]], '$y is unmodified');
35}
36
37{
38    my $x = Math::Matrix::Complex -> new([[0, 1, 2],
39                                          [5, 6, 7]]);
40    my $y = Math::Matrix::Complex -> new([[3, 4],
41                                          [8, 9]]);
42    my $z = $x -> catcol($y);
43    is(ref($z), 'Math::Matrix::Complex', '$z is a Math::Matrix::Complex');
44    is_deeply([ @$z ], [[0, 1, 2, 3, 4],
45                        [5, 6, 7, 8, 9]], '$z has the right values');
46
47    # Verify that modifying $z does not modify $x or $y.
48
49    my ($nrowz, $ncolz) = $z -> size();
50    for my $i (0 .. $nrowz - 1) {
51        for my $j (0 .. $ncolz - 1) {
52            $z -> [$i][$j] += 100;
53        }
54    }
55
56    is_deeply([ @$x ], [[0, 1, 2],
57                        [5, 6, 7]], '$x is unmodified');
58    is_deeply([ @$y ], [[3, 4],
59                        [8, 9]], '$y is unmodified');
60}
61
62{
63    my $x = Math::Matrix::Complex -> new([[0, 1, 2],
64                                          [5, 6, 7]]);
65    my $y = Math::Matrix::Complex -> new([]);
66    my $z = $x -> catcol($y);
67    is(ref($z), 'Math::Matrix::Complex', '$z is a Math::Matrix::Complex');
68    is_deeply([ @$z ], [[0, 1, 2],
69                        [5, 6, 7]], '$z has the right values');
70
71    # Verify that modifying $z does not modify $x or $y.
72
73    my ($nrowz, $ncolz) = $z -> size();
74    for my $i (0 .. $nrowz - 1) {
75        for my $j (0 .. $ncolz - 1) {
76            $z -> [$i][$j] += 100;
77        }
78    }
79
80    is_deeply([ @$x ], [[0, 1, 2],
81                        [5, 6, 7]], '$x is unmodified');
82    is_deeply([ @$y ], [], '$y is unmodified');
83}
84
85{
86    my $x = Math::Matrix::Complex -> new([]);
87    my $y = Math::Matrix::Complex -> new([[3, 4],
88                                          [8, 9]]);
89    my $z = $x -> catcol($y);
90    is(ref($z), 'Math::Matrix::Complex', '$z is a Math::Matrix::Complex');
91    is_deeply([ @$z ], [[3, 4],
92                        [8, 9]], '$z has the right values');
93
94    # Verify that modifying $z does not modify $x or $y.
95
96    my ($nrowz, $ncolz) = $z -> size();
97    for my $i (0 .. $nrowz - 1) {
98        for my $j (0 .. $ncolz - 1) {
99            $z -> [$i][$j] += 100;
100        }
101    }
102
103    is_deeply([ @$x ], [], '$x is unmodified');
104    is_deeply([ @$y ], [[3, 4],
105                        [8, 9]], '$y is unmodified');
106}
107
108{
109    my $x = Math::Matrix::Complex -> new([]);
110    my $y = Math::Matrix::Complex -> new([]);
111    my $z = $x -> catcol($y);
112    is(ref($z), 'Math::Matrix::Complex', '$z is a Math::Matrix::Complex');
113    is_deeply([ @$z ], [], '$z has the right values');
114
115    is_deeply([ @$x ], [], '$x is unmodified');
116    is_deeply([ @$y ], [], '$y is unmodified');
117}
118
119{
120    my $x = Math::Matrix::Complex -> new([[3]]);
121    my $z = $x -> catcol($x, $x, $x);
122    is(ref($z), 'Math::Matrix::Complex', '$z is a Math::Matrix::Complex');
123    is_deeply([ @$z ], [[3, 3, 3, 3]], '$z has the right values');
124    is_deeply([ @$x ], [[3]], '$x is unmodified');
125}
126
127{
128    my $x = Math::Matrix::Complex -> new([[3]]);
129    my $z = $x -> catcol();
130    is(ref($z), 'Math::Matrix::Complex', '$z is a Math::Matrix::Complex');
131    is_deeply([ @$z ], [[3]], '$z has the right values');
132    is_deeply([ @$x ], [[3]], '$x is unmodified');
133}
134