-
Notifications
You must be signed in to change notification settings - Fork 21k
Expand file tree
/
Copy pathMatrixDeterminantTest.java
More file actions
39 lines (31 loc) · 1.07 KB
/
MatrixDeterminantTest.java
File metadata and controls
39 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
class MatrixDeterminantTest {
@Test
void test2x2Matrix() {
double[][] matrix = {{1, 2}, {3, 4}};
assertEquals(-2, MatrixDeterminant.determinant(matrix), 1e-9);
}
@Test
void test3x3Matrix() {
double[][] matrix = {{2, 0, 1}, {3, 0, 0}, {5, 1, 1}};
assertEquals(3, MatrixDeterminant.determinant(matrix), 1e-9);
}
@Test
void test1x1Matrix() {
double[][] matrix = {{5}};
assertEquals(5, MatrixDeterminant.determinant(matrix), 1e-9);
}
@Test
void testSingularMatrix() {
double[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
assertEquals(0, MatrixDeterminant.determinant(matrix), 1e-9);
}
@Test
void testNonSquareMatrix() {
double[][] matrix = {{1, 2, 3}, {4, 5, 6}};
assertThrows(IllegalArgumentException.class, () -> MatrixDeterminant.determinant(matrix));
}
}