Skip to content

Commit b7a36c9

Browse files
committed
Add diagonal test.
1 parent a904f9c commit b7a36c9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/MatrixTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ public function testMultiplyScalar() {
227227
$this->assertEquals(4, $multiplied->get(2, 2));
228228
}
229229

230+
public function testDiagonal() {
231+
$matrix = new Matrix([
232+
[1, 2, 3],
233+
[4, 5, 6],
234+
[7, 8, 9]
235+
]);
236+
237+
$diagonal = $matrix->diagonal();
238+
239+
$this->assertEquals(1, $matrix->rows);
240+
$this->assertEquals(3, $matrix->columns);
241+
$this->assertEquals(1, $matix->get(0, 1));
242+
$this->assertEquals(5, $matix->get(0, 1));
243+
$this->assertEquals(9, $matix->get(0, 1));
244+
}
245+
230246
public function testTrace() {
231247
$matrix = new Matrix([
232248
[1, 2, 3],
@@ -331,4 +347,4 @@ public function testToString() {
331347

332348
$this->assertEquals('[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]', (string) $matrix);
333349
}
334-
}
350+
}

0 commit comments

Comments
 (0)