Skip to content

Commit bd77409

Browse files
authored
adding matrix identity test method
1 parent b1498ce commit bd77409

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test/com/jwetherell/algorithms/data_structures/test/MatrixTests.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.jwetherell.algorithms.data_structures.test;
22

33
import static org.junit.Assert.assertTrue;
4-
4+
import static org.junit.Assert.fail;
5+
import static org.junit.Assert.assertArrayEquals;
56
import org.junit.Test;
67

78
import com.jwetherell.algorithms.data_structures.Matrix;
@@ -86,4 +87,29 @@ public void testMatrix() {
8687
Matrix<Integer> matrix9 = matrix7.multiply(matrix8);
8788
assertTrue("Matrix multiplication error. matrix9="+matrix9+" result4"+result4, matrix9.equals(result4));
8889
}
90+
91+
@Test
92+
public void testIdentityMethod1() {
93+
Matrix<Integer> matrix = new Matrix<Integer>(2, 2);
94+
matrix.set(0, 0, 0);
95+
matrix.set(0, 1, 0);
96+
matrix.set(1, 0, 0);
97+
matrix.set(1, 1, 0);
98+
99+
Matrix<Integer> expectedResult = new Matrix<Integer>(2, 2);
100+
expectedResult.set(0, 0, 1);
101+
expectedResult.set(0, 1, 0);
102+
expectedResult.set(1, 0, 0);
103+
expectedResult.set(1, 1, 1);
104+
105+
try{
106+
matrix = matrix.identity();
107+
}
108+
catch(Exception ex){
109+
fail();
110+
}
111+
112+
assertArrayEquals(expectedResult.getRow(0), matrix.getRow(0));
113+
assertArrayEquals(expectedResult.getRow(1), matrix.getRow(1));
114+
}
89115
}

0 commit comments

Comments
 (0)