diff --git a/src/test/java/com/mattrixwv/matrix/TestIntegerMatrix.java b/src/test/java/com/mattrixwv/matrix/TestIntegerMatrix.java index 7ce8f76..03b47c2 100644 --- a/src/test/java/com/mattrixwv/matrix/TestIntegerMatrix.java +++ b/src/test/java/com/mattrixwv/matrix/TestIntegerMatrix.java @@ -1113,4 +1113,62 @@ public class TestIntegerMatrix{ }); assertEquals("IntegerMatrix 10x10 failed determinant2", -10000000, matrix.determinant()); } + + @Test + public void testCofactor(){ + //1x1 + IntegerMatrix matrix = new IntegerMatrix(grid1); + IntegerMatrix correctMatrix = new IntegerMatrix(grid1); + assertEquals("IntegerMatrix 1x1 failed cofactor", correctMatrix, matrix.cofactor()); + + //2x2 + matrix = new IntegerMatrix(grid2); + correctMatrix = new IntegerMatrix(new int[][]{ + {2, -1}, + {-2, 1} + }); + assertEquals("IntegerMatrix 2x2 failed cofactor", correctMatrix, matrix.cofactor()); + + //3x3 + matrix = new IntegerMatrix(grid3); + correctMatrix = new IntegerMatrix(3, 3, 0); + assertEquals("IntegerMatrix 3x3 failed cofactor1", correctMatrix, matrix.cofactor()); + matrix = new IntegerMatrix(new int[][]{ + {1, 4, 2}, + {2, 4, 1}, + {4, 1, 2} + }); + correctMatrix = new IntegerMatrix(new int[][]{ + {7, 0, -14}, + {-6, -6, 15}, + {-4, 3, -4} + }); + assertEquals("IntegerMatrix 3x3 failed cofactor2", correctMatrix, matrix.cofactor()); + + //4x4 + matrix = new IntegerMatrix(grid4); + correctMatrix = new IntegerMatrix(4, 4, 0); + assertEquals("IntegerMatrix 4x4 failed cofactor1", correctMatrix, matrix.cofactor()); + matrix = new IntegerMatrix(new int[][]{ + {1, 2, 3, 4}, + {2, 3, 4, 1}, + {3, 4, 1, 2}, + {4, 1, 2, 3} + }); + correctMatrix = new IntegerMatrix(new int[][]{ + {-36, 4, 4, 44}, + {4, 4, 44, -36}, + {4, 44, -36, 4}, + {44, -36, 4, 4} + }); + assertEquals("IntegerMatrix 4x4 failed cofactor2", correctMatrix, matrix.cofactor()); + + //10x10 + //?Skipping 10x10 test because test took > 5s by itself + /* + matrix = new IntegerMatrix(grid10); + correctMatrix = new IntegerMatrix(10, 10, 0); + assertEquals("IntegerMatrix 10x10 failed cofactor1", correctMatrix, matrix.cofactor()); + */ + } }