Skip to content

Commit c243140

Browse files
committed
Add test cases for 1by1 matrix and non-rectangular matrix
1 parent 410d22f commit c243140

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ public class MatrixMultiplicationTest {
1010

1111
private static final double EPSILON = 1e-9; // for floating point comparison
1212

13+
@Test
14+
void testMultiply1by1(){
15+
double[][] matrixA = {{1.0}};
16+
double[][] matrixB = {{2.0}};
17+
double[][] expected = {{2.0}};
18+
19+
double[][] result = MatrixMultiplication.multiply(matrixA, matrixB);
20+
assertMatrixEquals(expected, result);
21+
}
22+
1323
@Test
1424
void testMultiply2by2() {
1525
double[][] matrixA = {{1.0, 2.0}, {3.0, 4.0}};
@@ -30,6 +40,16 @@ void testMultiply3by2and2by1() {
3040
assertMatrixEquals(expected, result);
3141
}
3242

43+
@Test
44+
void testMultiplyNonRectangularMatrices() {
45+
double[][] matrixA = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}};
46+
double[][] matrixB = {{7.0, 8.0}, {9.0, 10.0}, {11.0, 12.0}};
47+
double[][] expected = {{58.0, 64.0}, {139.0, 154.0}};
48+
49+
double[][] result = MatrixMultiplication.multiply(matrixA, matrixB);
50+
assertMatrixEquals(expected, result);
51+
}
52+
3353
@Test
3454
void testNullMatrixA() {
3555
double[][] b = {{1, 2}, {3, 4}};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy