Skip to content

Commit ca40a2b

Browse files
committed
Updated files
1 parent 56baf84 commit ca40a2b

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/main/java/com/thealgorithms/matrix/MatrixMultiplication.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ public static double[][] multiply(double[][] matrixA, double[][] matrixB) {
1919
}
2020

2121
// Check for empty matrices
22-
if (matrixA.length == 0
23-
|| matrixB.length == 0
24-
|| matrixA[0].length == 0
25-
|| matrixB[0].length == 0) {
22+
if (matrixA.length == 0 || matrixB.length == 0 || matrixA[0].length == 0 || matrixB[0].length == 0) {
2623
throw new IllegalArgumentException("Input matrices must not be empty");
27-
}
24+
}
2825

2926
// Validate the matrix dimensions
3027
if (matrixA[0].length != matrixB.length) {

src/test/java/com/thealgorithms/matrix/MatrixMultiplicationTest.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.thealgorithms.matrix;
22

3-
import org.junit.jupiter.api.Test;
4-
import static org.junit.jupiter.api.Assertions.assertThrows;
53
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
65
import static org.junit.jupiter.api.Assertions.assertTrue;
76

7+
import org.junit.jupiter.api.Test;
8+
9+
810
public class MatrixMultiplicationTest {
911

1012
private static final double EPSILON = 1e-9; // for floating point comparison
@@ -32,24 +34,21 @@ void testMultiply3by2and2by1() {
3234
@Test
3335
void testNullMatrixA() {
3436
double[][] b = {{1, 2}, {3, 4}};
35-
assertThrows(IllegalArgumentException.class,
36-
() -> MatrixMultiplication.multiply(null, b));
37+
assertThrows(IllegalArgumentException.class, () -> MatrixMultiplication.multiply(null, b));
3738
}
3839

3940
@Test
4041
void testNullMatrixB() {
4142
double[][] a = {{1, 2}, {3, 4}};
42-
assertThrows(IllegalArgumentException.class,
43-
() -> MatrixMultiplication.multiply(a, null));
43+
assertThrows(IllegalArgumentException.class, () -> MatrixMultiplication.multiply(a, null));
4444
}
4545

4646
@Test
4747
void testMultiplyNull() {
4848
double[][] matrixA = {{1.0, 2.0}, {3.0, 4.0}};
4949
double[][] matrixB = null;
5050

51-
Exception exception = assertThrows(IllegalArgumentException.class,
52-
() -> MatrixMultiplication.multiply(matrixA, matrixB));
51+
Exception exception = assertThrows(IllegalArgumentException.class, () -> MatrixMultiplication.multiply(matrixA, matrixB));
5352

5453
String expectedMessage = "Input matrices cannot be null";
5554
String actualMessage = exception.getMessage();
@@ -61,16 +60,14 @@ void testMultiplyNull() {
6160
void testIncompatibleDimensions() {
6261
double[][] a = {{1.0, 2.0}};
6362
double[][] b = {{1.0, 2.0}};
64-
assertThrows(IllegalArgumentException.class,
65-
() -> MatrixMultiplication.multiply(a, b));
63+
assertThrows(IllegalArgumentException.class, () -> MatrixMultiplication.multiply(a, b));
6664
}
6765

6866
@Test
6967
void testEmptyMatrices() {
7068
double[][] a = new double[0][0];
7169
double[][] b = new double[0][0];
72-
assertThrows(IllegalArgumentException.class,
73-
() -> MatrixMultiplication.multiply(a, b));
70+
assertThrows(IllegalArgumentException.class, () -> MatrixMultiplication.multiply(a, b));
7471
}
7572

7673
private void assertMatrixEquals(double[][] expected, double[][] actual) {

0 commit comments

Comments
 (0)