2
2
3
3
namespace MatrixTest \Operations ;
4
4
5
+ use Matrix \Exception ;
5
6
use Matrix \Matrix ;
6
7
use Matrix \Operations ;
7
8
use MatrixTest \BaseTestAbstract ;
8
- use function Matrix \multiply ;
9
9
10
10
class multiplyTest extends BaseTestAbstract
11
11
{
@@ -21,7 +21,7 @@ public function testMultiplicationFunctionStatic($expected, $value1, $value2)
21
21
// Must return an object of the correct type...
22
22
$ this ->assertIsMatrixObject ($ result );
23
23
// ... containing the correct data
24
- $ this ->assertMatrixValues ( $ result , count ( $ expected), count ( $ expected [ 0 ]), $ expected );
24
+ $ this ->assertSame ( $ expected, $ result -> toArray () );
25
25
}
26
26
27
27
/**
@@ -35,17 +35,71 @@ public function testMultiplicationInvoker($expected, $value1, $value2)
35
35
// Must return an object of the correct type...
36
36
$ this ->assertIsMatrixObject ($ matrix );
37
37
// ... containing the correct data
38
- $ this ->assertMatrixValues ( $ result , count ( $ expected), count ( $ expected [ 0 ]), $ expected );
38
+ $ this ->assertSame ( $ expected, $ result -> toArray () );
39
39
// Verify that the original matrix remains unchanged
40
40
$ this ->assertOriginalMatrixIsUnchanged ($ value1 , $ matrix );
41
41
}
42
42
43
43
public function dataProvider ()
44
44
{
45
45
return [
46
- [
46
+ ' square - 2x2 * 2x2 ' => [
47
47
[[-14 , 20 ], [-30 , 44 ]],
48
- [[1 , 2 ], [3 , 4 ]], [[-2 , 4 ], [-6 , 8 ]],
48
+ [[1 , 2 ], [3 , 4 ]],
49
+ [[-2 , 4 ], [-6 , 8 ]],
50
+ ],
51
+ 'row vector/column vector ' => [
52
+ [[32 ]],
53
+ [[1 , 2 , 3 ]],
54
+ [[4 ], [5 ], [6 ]],
55
+ ],
56
+ 'column vector/row vector ' => [
57
+ [[4 , 5 , 6 ], [8 , 10 , 12 ], [12 , 15 , 18 ]],
58
+ [[1 ], [2 ], [3 ]],
59
+ [[4 , 5 , 6 ]],
60
+ ],
61
+ 'matrix 3x2 + 2x3 ' => [
62
+ [[50 , 68 ], [122 ,167 ]],
63
+ [[1 , 2 , 3 ], [4 , 5 , 6 ]],
64
+ [[7 , 10 ], [8 , 11 ], [9 , 12 ]],
65
+ ],
66
+ 'matrix 2x3 / 3x2 ' => [
67
+ [[47 , 52 , 57 ], [64 , 71 , 78 ], [81 , 90 , 99 ]],
68
+ [[1 , 4 ], [2 , 5 ], [3 , 6 ]],
69
+ [[7 , 8 , 9 ], [10 , 11 , 12 ]],
70
+ ],
71
+ ];
72
+ }
73
+
74
+ /**
75
+ * @dataProvider dataProviderException
76
+ */
77
+ public function testMultiplicationException ($ value1 , $ value2 )
78
+ {
79
+ $ this ->expectException (Exception::class);
80
+ $ this ->expectExceptionMessage ('Matrices have mismatched dimensions ' );
81
+
82
+ Operations::multiply ($ value1 , $ value2 );
83
+ }
84
+
85
+ public function dataProviderException ()
86
+ {
87
+ return [
88
+ 'row vector/row vector ' => [
89
+ [[1 , 2 , 3 ]],
90
+ [[4 , 5 , 6 ]],
91
+ ],
92
+ 'column vector/column vector ' => [
93
+ [[1 ], [2 ], [3 ]],
94
+ [[4 ], [5 ], [6 ]],
95
+ ],
96
+ 'matrix 3x2 + 3x2 ' => [
97
+ [[1 , 2 , 3 ], [4 , 5 , 6 ]],
98
+ [[7 , 8 , 9 ], [10 , 11 , 12 ]],
99
+ ],
100
+ 'matrix 2x3 / 2x3 ' => [
101
+ [[1 , 4 ], [2 , 5 ], [3 , 6 ]],
102
+ [[7 , 10 ], [8 , 11 ], [9 , 12 ]],
49
103
],
50
104
];
51
105
}
0 commit comments