@@ -3,7 +3,7 @@ use Math::Matrix;
33plan 4 ;
44
55my $ 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 ]] );
77my $ i = Math::Matrix. new-identity( 3 );
88
99subtest {
@@ -23,56 +23,50 @@ subtest {
2323
2424subtest {
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
3939subtest {
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
6057subtest {
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