1
1
package com .thealgorithms .matrix ;
2
2
3
- import org .junit .jupiter .api .Test ;
4
- import static org .junit .jupiter .api .Assertions .assertThrows ;
5
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
6
5
import static org .junit .jupiter .api .Assertions .assertTrue ;
7
6
7
+ import org .junit .jupiter .api .Test ;
8
+
9
+
8
10
public class MatrixMultiplicationTest {
9
11
10
12
private static final double EPSILON = 1e-9 ; // for floating point comparison
@@ -32,24 +34,21 @@ void testMultiply3by2and2by1() {
32
34
@ Test
33
35
void testNullMatrixA () {
34
36
double [][] b = {{1 , 2 }, {3 , 4 }};
35
- assertThrows (IllegalArgumentException .class ,
36
- () -> MatrixMultiplication .multiply (null , b ));
37
+ assertThrows (IllegalArgumentException .class , () -> MatrixMultiplication .multiply (null , b ));
37
38
}
38
39
39
40
@ Test
40
41
void testNullMatrixB () {
41
42
double [][] a = {{1 , 2 }, {3 , 4 }};
42
- assertThrows (IllegalArgumentException .class ,
43
- () -> MatrixMultiplication .multiply (a , null ));
43
+ assertThrows (IllegalArgumentException .class , () -> MatrixMultiplication .multiply (a , null ));
44
44
}
45
45
46
46
@ Test
47
47
void testMultiplyNull () {
48
48
double [][] matrixA = {{1.0 , 2.0 }, {3.0 , 4.0 }};
49
49
double [][] matrixB = null ;
50
50
51
- Exception exception = assertThrows (IllegalArgumentException .class ,
52
- () -> MatrixMultiplication .multiply (matrixA , matrixB ));
51
+ Exception exception = assertThrows (IllegalArgumentException .class , () -> MatrixMultiplication .multiply (matrixA , matrixB ));
53
52
54
53
String expectedMessage = "Input matrices cannot be null" ;
55
54
String actualMessage = exception .getMessage ();
@@ -61,16 +60,14 @@ void testMultiplyNull() {
61
60
void testIncompatibleDimensions () {
62
61
double [][] a = {{1.0 , 2.0 }};
63
62
double [][] b = {{1.0 , 2.0 }};
64
- assertThrows (IllegalArgumentException .class ,
65
- () -> MatrixMultiplication .multiply (a , b ));
63
+ assertThrows (IllegalArgumentException .class , () -> MatrixMultiplication .multiply (a , b ));
66
64
}
67
65
68
66
@ Test
69
67
void testEmptyMatrices () {
70
68
double [][] a = new double [0 ][0 ];
71
69
double [][] b = new double [0 ][0 ];
72
- assertThrows (IllegalArgumentException .class ,
73
- () -> MatrixMultiplication .multiply (a , b ));
70
+ assertThrows (IllegalArgumentException .class , () -> MatrixMultiplication .multiply (a , b ));
74
71
}
75
72
76
73
private void assertMatrixEquals (double [][] expected , double [][] actual ) {
0 commit comments