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 => 12;
19
20{
21    my $x = Math::Matrix::Complex -> new([[1, 2, 3],
22                                          [4, 5, 6],
23                                          [7, 8, 9]]);
24    my $y = $x -> transpose($x);
25
26    is(ref($y), 'Math::Matrix::Complex', '$y is a Math::Matrix::Complex');
27    is_deeply([ @$y ], [[1, 4, 7],
28                        [2, 5, 8],
29                        [3, 6, 9]], '$y has the right values');
30
31    # Verify that modifying $y does not modify $x.
32
33    my ($nrowy, $ncoly) = $y -> size();
34    for my $i (0 .. $nrowy - 1) {
35        for my $j (0 .. $ncoly - 1) {
36            $y -> [$i][$j] += 100;
37        }
38    }
39
40    is_deeply([ @$x ], [[1, 2, 3],
41                        [4, 5, 6],
42                        [7, 8, 9]], '$x is unmodified');
43}
44
45{
46    my $x = Math::Matrix::Complex -> new([[1, 2],
47                                          [4, 5]]);
48    my $y = $x -> transpose($x);
49
50    is(ref($y), 'Math::Matrix::Complex', '$y is a Math::Matrix::Complex');
51    is_deeply([ @$y ], [[1, 4],
52                        [2, 5]], '$y has the right values');
53
54    # Verify that modifying $y does not modify $x.
55
56    my ($nrowy, $ncoly) = $y -> size();
57    for my $i (0 .. $nrowy - 1) {
58        for my $j (0 .. $ncoly - 1) {
59            $y -> [$i][$j] += 100;
60        }
61    }
62
63    is_deeply([ @$x ], [[1, 2],
64                        [4, 5]], '$x is unmodified');
65}
66
67{
68    my $x = Math::Matrix::Complex -> new([[1]]);
69    my $y = $x -> transpose($x);
70
71    is(ref($y), 'Math::Matrix::Complex', '$y is a Math::Matrix::Complex');
72    is_deeply([ @$y ], [[1]], '$y has the right values');
73
74    # Verify that modifying $y does not modify $x.
75
76    my ($nrowy, $ncoly) = $y -> size();
77    for my $i (0 .. $nrowy - 1) {
78        for my $j (0 .. $ncoly - 1) {
79            $y -> [$i][$j] += 100;
80        }
81    }
82
83    is_deeply([ @$x ], [[1]], '$x is unmodified');
84}
85
86{
87    my $x = Math::Matrix::Complex -> new([]);
88    my $y = $x -> transpose($x);
89
90    is(ref($y), 'Math::Matrix::Complex', '$y is a Math::Matrix::Complex');
91    is_deeply([ @$y ], [], '$y has the right values');
92    is_deeply([ @$x ], [], '$x is unmodified');
93}
94