Skip to content

Commit c395405

Browse files
committed
fix rest structural tests
1 parent f164c70 commit c395405

3 files changed

Lines changed: 36 additions & 40 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ Works analogous to add - it's just for convenance.
611611

612612
### add-row
613613

614-
Add a vector (row or col of some matrix) to a row of the matrix. In this example we add (2,3) to the second row.
614+
Add a vector (row or col of some matrix) to a row of the matrix. In this example we add (2,3) to the second row. Instead of a matrix you can also give as parameter the raw data of a matrix as new would receive it.
615615

616616
Math::Matrix.new( [[1,2],[3,4]] ).add-row(1,(2,3));
617617

lib/Math/Matrix.pod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ Works analogous to add - it's just for convenance.
638638
639639
Add a vector (row or col of some matrix) to a row of the matrix.
640640
In this example we add (2,3) to the second row.
641+
Instead of a matrix you can also give as parameter the raw data of a matrix as
642+
new would receive it.
641643
642644
Math::Matrix.new( [[1,2],[3,4]] ).add-row(1,(2,3));
643645

t/052-matrix-struct-operation.t

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use Math::Matrix;
33
plan 4;
44

55
my $a = Math::Matrix.new( [[1,2,3],[2,3,4],[3,4,5]] );
6-
my $b = Math::Matrix.new( [[7,8],[9,10],[11,12]] );
6+
my $b = Math::Matrix.new( [[7,8],[9,10]] );
77
my $i = Math::Matrix.new-identity( 3 );
88

99
subtest {
@@ -23,56 +23,50 @@ subtest {
2323

2424
subtest {
2525
plan 8;
26-
ok $a.swap-rows(0, 2) ~~ Math::Matrix.new([[3,4,5],[2,3,4],[1,2,3]]), "swap two rows";
27-
ok $a.swap-rows(2, 1) ~~ Math::Matrix.new([[1,2,3],[3,4,5],[2,3,4]]), "swap another two rows";
28-
dies-ok { ok $a.swap-rows(5, 1); }, "first row number out of bound";
29-
dies-ok { ok $a.swap-rows(1, -3); }, "second row number out of bound";
26+
ok $a.swap-rows(0, 2) ~~ Math::Matrix.new([[3,4,5],[2,3,4],[1,2,3]]), "swap two rows";
27+
ok $a.swap-rows(2, 1) ~~ Math::Matrix.new([[1,2,3],[3,4,5],[2,3,4]]), "swap another two rows";
28+
dies-ok { ok $a.swap-rows(5, 1); }, "first row number out of bound";
29+
dies-ok { ok $a.swap-rows(1, -3); }, "second row number out of bound";
3030

31-
ok $a.swap-columns(0, 2) ~~ Math::Matrix.new([[3,2,1],[4,3,2],[5,4,3]]), "swap two columns";
32-
ok $a.swap-columns(2, 1) ~~ Math::Matrix.new([[1,3,2],[2,4,3],[3,5,4]]), "swap another two columns";
33-
dies-ok { ok $a.swap-columns(3, 1); }, "first column number out of bound";
34-
dies-ok { ok $a.swap-columns(1, -5); }, "second column number out of bound";
31+
ok $a.swap-columns(0, 2) ~~ Math::Matrix.new([[3,2,1],[4,3,2],[5,4,3]]),"swap two columns";
32+
ok $a.swap-columns(2, 1) ~~ Math::Matrix.new([[1,3,2],[2,4,3],[3,5,4]]),"swap another two columns";
33+
dies-ok { ok $a.swap-columns(3, 1); }, "first column number out of bound";
34+
dies-ok { ok $a.swap-columns(1, -5); }, "second column number out of bound";
3535

3636
}, "Swap";
3737

3838

3939
subtest {
40+
my $answer1 = Math::Matrix.new([[1,0,0],[0,1,0],[0,0,1],[1,2,3],[2,3,4],[3,4,5]]);
41+
my $answer2 = Math::Matrix.new([[1,0,0,1,2,3],[0,1,0,2,3,4],[0,0,1,3,4,5]]);
42+
4043
plan 8;
41-
ok $a.prepend-vertically($i) ~~ Math::Matrix.new([[1,0,0],[0,1,0],[0,0,1],[3,4,5],[1,2,3],[2,3,4],[3,4,5]]),
42-
"prepend vertically matrix";
43-
ok $a.prepend-vertically([1,0,0],[0,1,0],[0,0,1])
44-
~~ Math::Matrix.new([[1,0,0],[0,1,0],[0,0,1],[3,4,5],[1,2,3],[2,3,4],[3,4,5]]),
45-
"prepend vertically data";
46-
dies-ok { $a.prepend-vertically($b) }, "can not prepend vertically matrix with different size";
47-
dies-ok { $a.prepend-vertically([[1]]) }, "can not prepend vertically data matrix with different size";
48-
49-
ok $a.prepend-horizontally($i) ~~ Math::Matrix.new([[1,0,0,1,2,3],[0,1,0,2,3,4],[0,0,1,3,4,5]]),
50-
"prepend horizontally matrix";
51-
ok $a.prepend-horizontally([1,0,0],[0,1,0],[0,0,1])
52-
~~ Math::Matrix.new([[1,0,0,1,2,3],[0,1,0,2,3,4],[0,0,1,3,4,5]]),
53-
"prepend horizontally data";
54-
dies-ok { $a.prepend-horizontally($b) }, "can not prepend horizontally matrix with different size";
55-
dies-ok { $a.prepend-horizontally([[1]]) }, "can not prepend horizontally data matrix with different size";
44+
ok $a.prepend-vertically($i) ~~ $answer1, "prepend vertically matrix";
45+
ok $a.prepend-vertically([[1,0,0],[0,1,0],[0,0,1]]) ~~ $answer1, "prepend vertically data";
46+
dies-ok { $a.prepend-vertically($b) }, "can not prepend vertically matrix with different size";
47+
dies-ok { $a.prepend-vertically([[1]]) }, "can not prepend vertically data matrix with different size";
48+
49+
ok $a.prepend-horizontally($i) ~~ $answer2, "prepend horizontally matrix";
50+
ok $a.prepend-horizontally([[1,0,0],[0,1,0],[0,0,1]]) ~~ $answer2, "prepend horizontally data";
51+
dies-ok { $a.prepend-horizontally($b) }, "can not prepend horizontally matrix with different size";
52+
dies-ok { $a.prepend-horizontally([[1]]) }, "can not prepend horizontally data matrix with different size";
5653

5754
}, "Prepend";
5855

5956

6057
subtest {
58+
my $answer1 = Math::Matrix.new([[1,2,3],[2,3,4],[3,4,5],[1,0,0],[0,1,0],[0,0,1]]);
59+
my $answer2 = Math::Matrix.new([[1,2,3,1,0,0],[2,3,4,0,1,0],[3,4,5,0,0,1]]);
60+
6161
plan 8;
62-
ok $a.append-vertically($i) ~~ Math::Matrix.new([[3,4,5],[1,2,3],[2,3,4],[3,4,5],[1,0,0],[0,1,0],[0,0,1]]),
63-
"append vertically matrix";
64-
ok $a.append-vertically([1,0,0],[0,1,0],[0,0,1])
65-
~~ Math::Matrix.new([[3,4,5],[1,2,3],[2,3,4],[3,4,5],[1,0,0],[0,1,0],[0,0,1]]),
66-
"append vertically data";
67-
dies-ok { $a.append-vertically($b) }, "can not append vertically matrix with different size";
68-
dies-ok { $a.append-vertically([[1]]) }, "can not append vertically data matrix with different size";
69-
70-
ok $a.append-horizontally($i) ~~ Math::Matrix.new([[1,2,3,1,0,0],[2,3,4,0,1,0],[3,4,5,0,0,1]]),
71-
"append horizontally matrix";
72-
ok $a.append-horizontally([1,0,0],[0,1,0],[0,0,1])
73-
~~ Math::Matrix.new([[1,2,3,1,0,0],[2,3,4,0,1,0],[3,4,5,0,0,1]]),
74-
"append horizontally data";
75-
dies-ok { $a.append-horizontally($b) }, "can not append horizontally matrix with different size";
76-
dies-ok { $a.append-horizontally([[1]]) }, "can not append horizontally data matrix with different size";
62+
ok $a.append-vertically($i) ~~ $answer1, "append vertically matrix";
63+
ok $a.append-vertically([[1,0,0],[0,1,0],[0,0,1]]) ~~ $answer1, "append vertically data";
64+
dies-ok { $a.append-vertically($b) }, "can not append vertically matrix with different size";
65+
dies-ok { $a.append-vertically([[1]]) }, "can not append vertically data matrix with different size";
66+
67+
ok $a.append-horizontally($i) ~~ $answer2, "append horizontally matrix";
68+
ok $a.append-horizontally([[1,0,0],[0,1,0],[0,0,1]]) ~~ $answer2, "append horizontally data";
69+
dies-ok { $a.append-horizontally($b) }, "can not append horizontally matrix with different size";
70+
dies-ok { $a.append-horizontally([[1]]) }, "can not append horizontally data matrix with different size";
7771

7872
}, "Append";

0 commit comments

Comments
 (0)