From 88f6734e6f1eae3ad4fdeb3bc9ef9187956c80c3 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Thu, 10 Feb 2022 16:17:32 +0000 Subject: [PATCH] Added LongMatrix --- .../com/mattrixwv/matrix/TestLongMatrix.java | 1311 +++++++++++++++++ 1 file changed, 1311 insertions(+) create mode 100644 src/test/java/com/mattrixwv/matrix/TestLongMatrix.java diff --git a/src/test/java/com/mattrixwv/matrix/TestLongMatrix.java b/src/test/java/com/mattrixwv/matrix/TestLongMatrix.java new file mode 100644 index 0000000..c8bdf68 --- /dev/null +++ b/src/test/java/com/mattrixwv/matrix/TestLongMatrix.java @@ -0,0 +1,1311 @@ +//Matrix/src/test/java/com/mattrixwv/matrix/TestLongMatrix.java +//Mattrixwv +// Created: 02-10-22 +//Modified: 02-10-22 +package com.mattrixwv.matrix; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + + +public class TestLongMatrix{ + //Grid 1x1 + private static final long[][] grid1 = { + {1} + }; + private static final long[][] transformGrid1_1 = { + {1} + }; + private static final long[][] transformGrid1_2 = { + {2} + }; + + //Grid 2x2 + private static final long[][] grid2 = { + {1, 2}, + {1, 2} + }; + private static final long[][] transformGrid2_1 = { + {1, 0}, + {1, 0} + }; + private static final long[][] transformGrid2_2 = { + {2, 3}, + {2, 3} + }; + + //Grid 3x3 + private static final long[][] grid3 = { + {1, 2, 3}, + {1, 2, 3}, + {1, 2, 3} + }; + private static final long[][] transformGrid3_1 = { + {2, 1, 0}, + {2, 1, 0}, + {2, 1, 0} + }; + private static final long[][] transformGrid3_2 = { + {2, 3, 4}, + {2, 3, 4}, + {2, 3, 4} + }; + + //Grid 4x4 + private static final long[][] grid4 = { + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4} + }; + private static final long[][] transformGrid4_1 = { + {3, 2, 1, 0}, + {3, 2, 1, 0}, + {3, 2, 1, 0}, + {3, 2, 1, 0} + }; + private static final long[][] transformGrid4_2 = { + {2, 3, 4, 5}, + {2, 3, 4, 5}, + {2, 3, 4, 5}, + {2, 3, 4, 5} + }; + + //Grid 10x10 + private static final long[][] grid10 = { + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + }; + private static final long[][] transformGrid10_1 = { + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} + }; + private static final long[][] transformGrid10_2 = { + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }; + + + @Test + public void testEquals(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + assertTrue("LongMatrix 1x1 failed equals LongMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals = matrix.equals(grid1); + assertTrue("LongMatrix 1x1 failed equals long[][].", gridEquals); + + //2x2 + matrix = new LongMatrix(grid2); + assertTrue("LongMatrix 2x2 failed equals LongMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals2 = matrix.equals(grid2); + assertTrue("LongMatrix 2x2 failed equals long[][].", gridEquals2); + + //3x3 + matrix = new LongMatrix(grid3); + assertTrue("LongMatrix 3x3 failed equals LongMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals3 = matrix.equals(grid3); + assertTrue("LongMatrix 3x3 failed equals long[][].", gridEquals3); + + //4x4 + matrix = new LongMatrix(grid4); + assertTrue("LongMatrix 4x4 failed equals LongMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals4 = matrix.equals(grid4); + assertTrue("LongMatrix 4x4 failed equals long[][].", gridEquals4); + + //10x10 + matrix = new LongMatrix(grid10); + assertTrue("LongMatrix = 10x10 failed equals LongMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals10 = matrix.equals(grid10); + assertTrue("LongMatrix 10x10 failed equals long[][].", gridEquals10); + } + + @Test + public void testGets(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + assertEquals("LongMatrix 1x1 failed get.", 1, matrix.get(0, 0)); + //GetRow + LongMatrix correctMatrix = new LongMatrix(new long[][]{{1}}); + assertEquals("LongMatrix 1x1 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new LongMatrix(new long[][]{{1}}); + assertEquals("LongMatrix 1x1 failed getCol.", correctMatrix, matrix.getCol(0)); + + //2x2 + matrix = new LongMatrix(grid2); + assertEquals("LongMatrix 2x2 failed get.", 1, matrix.get(0, 0)); + //GetRow + correctMatrix = new LongMatrix(new long[][]{{1, 2}}); + assertEquals("LongMatrix 2x2 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new LongMatrix(new long[][]{ + {1}, + {1} + }); + assertEquals("LongMatrix 2x2 failed getCol.", correctMatrix, matrix.getCol(0)); + + //3x3 + matrix = new LongMatrix(grid3); + assertEquals("LongMatrix 3x3 failed get.", 1, matrix.get(0, 0)); + //GetRow + correctMatrix = new LongMatrix(new long[][]{{1, 2, 3}}); + assertEquals("LongMatrix 3x3 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new LongMatrix(new long[][]{ + {1}, + {1}, + {1} + }); + assertEquals("LongMatrix 3x3 failed getCol.", correctMatrix, matrix.getCol(0)); + + //4x4 + matrix = new LongMatrix(grid4); + assertEquals("LongMatrix 4x4 failed get.", 1, matrix.get(0, 0)); + //GetRow + correctMatrix = new LongMatrix(new long[][]{{1, 2, 3, 4}}); + assertEquals("LongMatrix 4x4 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new LongMatrix(new long[][]{ + {1}, + {1}, + {1}, + {1} + }); + assertEquals("LongMatrix 4x4 failed getCol.", correctMatrix, matrix.getCol(0)); + + //10x10 + matrix = new LongMatrix(grid10); + assertEquals("LongMatrix 10x10 failed get.", 1, matrix.get(0, 0)); + //GetRow + correctMatrix = new LongMatrix(new long[][]{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}); + assertEquals("LongMatrix 10x10 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new LongMatrix(new long[][]{ + {1}, + {1}, + {1}, + {1}, + {1}, + {1}, + {1}, + {1}, + {1}, + {1} + }); + assertEquals("LongMatrix 10x10 failed getColumn.", correctMatrix, matrix.getCol(0)); + } + + @Test + public void testSets(){ + //1x1 + //Set + LongMatrix matrix = new LongMatrix(grid1); + matrix.set(0, 0, 2); + LongMatrix correctMatrix = new LongMatrix(new long[][]{{2}}); + assertEquals("LongMatrix 1x1 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new long[]{0}); + correctMatrix = new LongMatrix(new long[][]{{0}}); + assertEquals("LongMatrix 1x1 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new long[]{1}); + correctMatrix = new LongMatrix(new long[][]{{1}}); + assertEquals("LongMatrix 1x1 failed setCol.", correctMatrix, matrix); + + //2x2 + //Set + matrix = new LongMatrix(grid2); + matrix.set(0, 0, 3); + correctMatrix = new LongMatrix(new long[][]{ + {3, 2}, + {1, 2} + }); + assertEquals("LongMatrix 2x2 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(1, new long[]{2, 1}); + correctMatrix = new LongMatrix(new long[][]{ + {3, 2}, + {2, 1} + }); + assertEquals("LongMatrix 2x2 failed set row.", correctMatrix, matrix); + //SetColumn + matrix = new LongMatrix(grid2); + matrix.setCol(0, new long[]{3, 3}); + correctMatrix = new LongMatrix(new long[][]{ + {3, 2}, + {3, 2} + }); + assertEquals("LongMatrix 2x2 failed set row.", correctMatrix, matrix); + + //3x3 + //Set + matrix = new LongMatrix(grid3); + matrix.set(0, 0, 3); + correctMatrix = new LongMatrix(new long[][]{ + {3, 2, 3}, + {1, 2, 3}, + {1, 2, 3}, + }); + assertEquals("LongMatrix 3x3 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new long[]{0, 1, 2}); + correctMatrix = new LongMatrix(new long[][]{ + {0, 1, 2}, + {1, 2, 3}, + {1, 2, 3} + }); + assertEquals("LongMatrix 3x3 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new long[]{0, 0, 0}); + correctMatrix = new LongMatrix(new long[][]{ + {0, 1, 2}, + {0, 2, 3}, + {0, 2, 3} + }); + assertEquals("LongMatrix 3x3 failed setColumn.", correctMatrix, matrix); + + //4x4 + //Set + matrix = new LongMatrix(grid4); + matrix.set(0, 0, 3); + correctMatrix = new LongMatrix(new long[][]{ + {3, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4} + }); + assertEquals("LongMatrix 4x4 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new long[]{4, 3, 2, 1}); + correctMatrix = new LongMatrix(new long[][]{ + {4, 3, 2, 1}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4} + }); + assertEquals("LongMatrix 4x4 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new long[]{0, 0, 0, 0}); + correctMatrix = new LongMatrix(new long[][]{ + {0, 3, 2, 1}, + {0, 2, 3, 4}, + {0, 2, 3, 4}, + {0, 2, 3, 4} + }); + assertEquals("LongMatrix 4x4 failed setCol.", correctMatrix, matrix); + + //10x10 + //Set + matrix = new LongMatrix(grid10); + matrix.set(0, 0, 3); + correctMatrix = new LongMatrix(new long[][]{ + {3, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + }); + assertEquals("LongMatrix 10x10 failed setRow.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new long[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}); + correctMatrix = new LongMatrix(new long[][]{ + {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + }); + assertEquals("LongMatrix 10x10 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new long[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}); + correctMatrix = new LongMatrix(new long[][]{ + {0, 9, 8, 7, 6, 5, 4, 3, 2, 1}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 2, 3, 4, 5, 6, 7, 8, 9, 10} + }); + assertEquals("LongMatrix 10x10 failed setColumn.", correctMatrix, matrix); + } + + @Test + public void testAdds(){ + //1x1 + //AddRow + LongMatrix matrix = new LongMatrix(grid1); + matrix.addRow(new long[]{1}); + LongMatrix correctMatrix = new LongMatrix(new long[][]{{1}, {1}}); + assertEquals("LongMatrix 1x1 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new LongMatrix(grid1); + matrix.addCol(new long[]{1}); + correctMatrix = new LongMatrix(new long[][]{{1, 1}}); + assertEquals("LongMatrix 1x1 failed addCol.", correctMatrix, matrix); + + //2x2 + //AddRow + matrix = new LongMatrix(grid2); + matrix.addRow(new long[]{1, 2}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2}, + {1, 2}, + {1, 2} + }); + assertEquals("LongMatrix 2x2 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new LongMatrix(grid2); + matrix.addCol(new long[]{3, 3}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3}, + {1, 2, 3} + }); + assertEquals("LongMatrix 2x2 failed addCol.", correctMatrix, matrix); + + //3x3 + //AddRow + matrix = new LongMatrix(grid3); + matrix.addRow(new long[]{1, 2, 3}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3}, + {1, 2, 3}, + {1, 2, 3}, + {1, 2, 3} + }); + assertEquals("LongMatrix 3x3 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new LongMatrix(grid3); + matrix.addCol(new long[]{4, 4, 4}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4} + }); + assertEquals("LongMatrix 3x3 failed addCol.", correctMatrix, matrix); + + //4x4 + //AddRow + matrix = new LongMatrix(grid4); + matrix.addRow(new long[]{1, 2, 3, 4}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4} + }); + assertEquals("LongMatrix 4x4 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix.addCol(new long[]{5, 5, 5, 5, 5}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4, 5}, + {1, 2, 3, 4, 5}, + {1, 2, 3, 4, 5}, + {1, 2, 3, 4, 5}, + {1, 2, 3, 4, 5} + }); + assertEquals("LongMatrix 4x4 failed addCol.", correctMatrix, matrix); + + //10x10 + //AddRow + matrix = new LongMatrix(grid10); + matrix.addRow(new long[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + }); + assertEquals("LongMatrix 10x10 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new LongMatrix(grid10); + matrix.addCol(new long[]{11, 11, 11, 11, 11, 11, 11, 11, 11, 11}); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }); + assertEquals("LongMatrix 10x10 failed addColumn.", correctMatrix, matrix); + } + + @Test + public void testAppends(){ + //1x1 + //appendRight + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix secondMatrix = new LongMatrix(grid1); + LongMatrix correctMatrix = new LongMatrix(new long[][]{{1, 1}}); + assertEquals("LongMatrix 1x1 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new LongMatrix(new long[][]{ + {1}, + {1} + }); + assertEquals("LongMatrix 1x1 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //2x2 + //appendRight + matrix = new LongMatrix(grid2); + secondMatrix = new LongMatrix(grid2); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 1, 2}, + {1, 2, 1, 2} + }); + assertEquals("LongMatrix 2x2 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new LongMatrix(new long[][]{ + {1, 2}, + {1, 2}, + {1, 2}, + {1, 2} + }); + assertEquals("LongMatrix 2x2 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //3x3 + //appendRight + matrix = new LongMatrix(grid3); + secondMatrix = new LongMatrix(grid3); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 1, 2, 3}, + {1, 2, 3, 1, 2, 3}, + {1, 2, 3, 1, 2, 3} + }); + assertEquals("LongMatrix 3x3 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3}, + {1, 2, 3}, + {1, 2, 3}, + {1, 2, 3}, + {1, 2, 3}, + {1, 2, 3} + }); + assertEquals("LongMatrix 3x3 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //4x4 + //appendRight + matrix = new LongMatrix(grid4); + secondMatrix = new LongMatrix(grid4); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4, 1, 2, 3, 4}, + {1, 2, 3, 4, 1, 2, 3, 4}, + {1, 2, 3, 4, 1, 2, 3, 4}, + {1, 2, 3, 4, 1, 2, 3, 4} + }); + assertEquals("LongMatrix 4x4 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4} + }); + assertEquals("LongMatrix 4x4 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //10x10 + //appendRight + matrix = new LongMatrix(grid10); + secondMatrix = new LongMatrix(grid10); + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + }); + assertEquals("LongMatrix 10x10 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + }); + assertEquals("LongMatrix 10x10 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + } + + @Test + public void testAddition(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix transformMatrix = new LongMatrix(transformGrid1_1); + LongMatrix correctMatrix = new LongMatrix(new long[][]{{2}}); + assertEquals("LongMatrix 1x1 failed add LongMatrix.", correctMatrix, matrix.add(transformMatrix)); + assertEquals("LongMatrix 1x1 failed add scalar.", correctMatrix, matrix.add(1)); + + //2x2 + matrix = new LongMatrix(grid2); + transformMatrix = new LongMatrix(transformGrid2_1); + correctMatrix = new LongMatrix(new long[][]{ + {2, 2}, + {2, 2} + }); + assertEquals("LongMatrix 2x2 failed add LongMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 3}, + {2, 3} + }); + assertEquals("LongMatrix 2x2 failed add scalar.", correctMatrix, matrix.add(1)); + + //3x3 + matrix = new LongMatrix(grid3); + transformMatrix = new LongMatrix(transformGrid3_1); + correctMatrix = new LongMatrix(new long[][]{ + {3, 3, 3}, + {3, 3, 3}, + {3, 3, 3} + }); + assertEquals("LongMatrix 3x3 failed add LongMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 3, 4}, + {2, 3, 4}, + {2, 3, 4} + }); + assertEquals("LongMatrix 3x3 failed add scalar.", correctMatrix, matrix.add(1)); + + //4x4 + matrix = new LongMatrix(grid4); + transformMatrix = new LongMatrix(transformGrid4_1); + correctMatrix = new LongMatrix(new long[][]{ + {4, 4, 4, 4}, + {4, 4, 4, 4}, + {4, 4, 4, 4}, + {4, 4, 4, 4} + }); + assertEquals("LongMatrix 4x4 failed add LongMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 3, 4, 5}, + {2, 3, 4, 5}, + {2, 3, 4, 5}, + {2, 3, 4, 5} + }); + assertEquals("LongMatrix 4x4 failed add scalar.", correctMatrix, matrix.add(1)); + + //10x10 + matrix = new LongMatrix(grid10); + transformMatrix = new LongMatrix(transformGrid10_1); + correctMatrix = new LongMatrix(new long[][]{ + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10} + }); + assertEquals("LongMatrix 5x5 failed add LongMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 11} + }); + assertEquals("LongMatrix 10x10 failed add LongMatrix.", correctMatrix, matrix.add(1)); + } + + @Test + public void testSubtraction(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix transformMatrix = new LongMatrix(grid1); + LongMatrix correctMatrix = new LongMatrix(new long[][]{ + {0} + }); + assertEquals("LongMatrix 1x1 failed subtract LongMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + assertEquals("LongMatrix 1x1 failed subtract scalar.", correctMatrix, matrix.subtract(1)); + + //2x2 + matrix = new LongMatrix(grid2); + transformMatrix = new LongMatrix(grid2); + correctMatrix = new LongMatrix(2, 2, 0); + assertEquals("LongMatrix 2x2 failed subtract LongMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {0, 1}, + {0, 1} + }); + assertEquals("LongMatrix 2x2 failed subtract scalar.", correctMatrix, matrix.subtract(1)); + + //3x3 + matrix = new LongMatrix(grid3); + transformMatrix = new LongMatrix(grid3); + correctMatrix = new LongMatrix(3, 3, 0); + assertEquals("LongMatrix 3x3 failed subtract LongMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {0, 1, 2}, + {0, 1, 2}, + {0, 1, 2} + }); + assertEquals("LongMatrix 3x3 failed subtract scalar.", correctMatrix, matrix.subtract(1)); + + //4x4 + matrix = new LongMatrix(grid4); + transformMatrix = new LongMatrix(grid4); + correctMatrix = new LongMatrix(4, 4, 0); + assertEquals("LongMatrix 4x4 failed subtract LongMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {0, 1, 2, 3}, + {0, 1, 2, 3}, + {0, 1, 2, 3}, + {0, 1, 2, 3} + }); + assertEquals("LongMatrix 4x4 failed subtract scalar.", correctMatrix, matrix.subtract(1)); + + //10x10 + matrix = new LongMatrix(grid10); + transformMatrix = new LongMatrix(grid10); + correctMatrix = new LongMatrix(10, 10, 0); + assertEquals("LongMatrix 10x10 failed subtract LongMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new LongMatrix(new long[][]{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} + }); + assertEquals("LongMatrix 10x10 failed subtract scalar.", correctMatrix, matrix.subtract(1)); + } + + @Test + public void testMultiplication(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix transformMatrix = new LongMatrix(transformGrid1_2); + LongMatrix correctMatrix = new LongMatrix(transformGrid1_2); + assertEquals("LongMatrix 1x1 failed multiplication LongMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + assertEquals("LongMatrix 1x1 failed multiplication scalar.", correctMatrix, matrix.multiply(2)); + + //2x2 + matrix = new LongMatrix(grid2); + transformMatrix = new LongMatrix(transformGrid2_2); + correctMatrix = new LongMatrix(new long[][]{ + {6, 9}, + {6, 9} + }); + assertEquals("LongMatrix 2x2 failed multiplication LongMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + LongMatrix vector = new LongMatrix(new long[][]{ + {2}, + {3} + }); + correctMatrix = new LongMatrix(new long[][]{ + {8}, + {8} + }); + assertEquals("LongMatrix 2x2 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 4}, + {2, 4} + }); + assertEquals("LongMatrix 2x2 failed multiplication scalar.", correctMatrix, matrix.multiply(2)); + + //3x3 + matrix = new LongMatrix(grid3); + transformMatrix = new LongMatrix(transformGrid3_2); + correctMatrix = new LongMatrix(new long[][]{ + {12, 18, 24}, + {12, 18, 24}, + {12, 18, 24} + }); + assertEquals("LongMatrix 3x3 failed multiplication LongMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + vector = new LongMatrix(new long[][]{ + {2}, + {3}, + {4} + }); + correctMatrix = new LongMatrix(new long[][]{ + {20}, + {20}, + {20} + }); + assertEquals("LongMatrix 3x3 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 4, 6}, + {2, 4, 6}, + {2, 4, 6} + }); + assertEquals("LongMatrix 3x3 failed multiplication scalar.", correctMatrix, matrix.multiply(2)); + + //4x4 + matrix = new LongMatrix(grid4); + transformMatrix = new LongMatrix(transformGrid4_2); + correctMatrix = new LongMatrix(new long[][]{ + {20, 30, 40, 50}, + {20, 30, 40, 50}, + {20, 30, 40, 50}, + {20, 30, 40, 50}, + }); + assertEquals("LongMatrix 4x4 failed multiplication LongMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + vector = new LongMatrix(new long[][]{ + {2}, + {3}, + {4}, + {5} + }); + correctMatrix = new LongMatrix(new long[][]{ + {40}, + {40}, + {40}, + {40} + }); + assertEquals("LongMatrix 4x4 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 4, 6, 8}, + {2, 4, 6, 8}, + {2, 4, 6, 8}, + {2, 4, 6, 8} + }); + assertEquals("LongMatrix 4x4 failed multiplication scalar.", correctMatrix, matrix.multiply(2)); + + //10x10 + matrix = new LongMatrix(grid10); + transformMatrix = new LongMatrix(transformGrid10_2); + correctMatrix = new LongMatrix(new long[][]{ + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605}, + {110, 165, 220, 275, 330, 385, 440, 495, 550, 605} + }); + assertEquals("LongMatrix 10x10 failed multiplication LongMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + vector = new LongMatrix(new long[][]{ + {2}, + {3}, + {4}, + {5}, + {6}, + {7}, + {8}, + {9}, + {10}, + {11} + }); + correctMatrix = new LongMatrix(new long[][]{ + {440}, + {440}, + {440}, + {440}, + {440}, + {440}, + {440}, + {440}, + {440}, + {440} + }); + assertEquals("LongMatrix 10x10 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new LongMatrix(new long[][]{ + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}, + {2, 4, 6, 8, 10, 12, 14, 16, 18, 20} + }); + assertEquals("LongMatrix 10x10 failed multiplication scalar.", correctMatrix, matrix.multiply(2)); + } + + @Test + public void testDotProduct(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix transformMatrix = new LongMatrix(transformGrid1_2); + assertEquals("LongMatrix 1x1 failed dot product LongMatrix.", 2, matrix.dotProduct(transformMatrix)); + + //2x2 + matrix = new LongMatrix(grid2); + transformMatrix = new LongMatrix(transformGrid2_2); + assertEquals("LongMatrix 2x2 failed dot product LongMatrix.", 30, matrix.dotProduct(transformMatrix)); + + //3x3 + matrix = new LongMatrix(grid3); + transformMatrix = new LongMatrix(transformGrid3_2); + assertEquals("LongMatrix 3x3 failed dot product LongMatrix.", 162, matrix.dotProduct(transformMatrix)); + + //4x4 + matrix = new LongMatrix(grid4); + transformMatrix = new LongMatrix(transformGrid4_2); + assertEquals("LongMatrix 4x4 failed dot product LongMatrix.", 560, matrix.dotProduct(transformMatrix)); + + //10x10 + matrix = new LongMatrix(grid10); + transformMatrix = new LongMatrix(transformGrid10_2); + assertEquals("LongMatrix 10x10 failed dot product LongMatrix.", 35750, matrix.dotProduct(transformMatrix)); + } + + @Test + public void testHadamardProduct(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix transformMatrix = new LongMatrix(transformGrid1_2); + LongMatrix correctMatrix = new LongMatrix(new long[][]{{2}}); + assertEquals("LongMatrix 1x1 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //2x2 + matrix = new LongMatrix(grid2); + transformMatrix = new LongMatrix(transformGrid2_2); + correctMatrix = new LongMatrix(new long[][]{ + {2, 6}, + {2, 6} + }); + assertEquals("LongMatrix 2x2 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //3x3 + matrix = new LongMatrix(grid3); + transformMatrix = new LongMatrix(transformGrid3_2); + correctMatrix = new LongMatrix(new long[][]{ + {2, 6, 12}, + {2, 6, 12}, + {2, 6, 12} + }); + assertEquals("LongMatrix 3x3 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //4x4 + matrix = new LongMatrix(grid4); + transformMatrix = new LongMatrix(transformGrid4_2); + correctMatrix = new LongMatrix(new long[][]{ + {2, 6, 12, 20}, + {2, 6, 12, 20}, + {2, 6, 12, 20}, + {2, 6, 12, 20} + }); + assertEquals("LongMatrix 4x4 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //10x10 + matrix = new LongMatrix(grid10); + transformMatrix = new LongMatrix(transformGrid10_2); + correctMatrix = new LongMatrix(new long[][]{ + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110}, + {2, 6, 12, 20, 30, 42, 56, 72, 90, 110} + }); + assertEquals("LongMatrix 10x10 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + } + + @Test + public void testTranspose(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix correctMatrix = new LongMatrix(new long[][]{{1}}); + assertEquals("LongMatrix 1x1 failed transpose.", correctMatrix, matrix.transpose()); + + //2x2 + matrix = new LongMatrix(grid2); + correctMatrix = new LongMatrix(new long[][]{ + {1, 1}, + {2, 2} + }); + assertEquals("LongMatrix 2x2 failed transpose.", correctMatrix, matrix.transpose()); + + //3x3 + matrix = new LongMatrix(grid3); + correctMatrix = new LongMatrix(new long[][]{ + {1, 1, 1}, + {2, 2, 2}, + {3, 3, 3} + }); + assertEquals("LongMatrix 3x3 failed transpose.", correctMatrix, matrix.transpose()); + + //4x4 + matrix = new LongMatrix(grid4); + correctMatrix = new LongMatrix(new long[][]{ + {1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4} + }); + assertEquals("LongMatrix 4x4 failed transpose.", correctMatrix, matrix.transpose()); + + //10x10 + matrix = new LongMatrix(grid10); + correctMatrix = new LongMatrix(new long[][]{ + {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, + {2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, + {3, 3, 3, 3, 3, 3, 3, 3, 3, 3}, + {4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {6, 6, 6, 6, 6, 6, 6, 6, 6, 6}, + {7, 7, 7, 7, 7, 7, 7, 7, 7, 7}, + {8, 8, 8, 8, 8, 8, 8, 8, 8, 8}, + {9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, + {10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, + }); + assertEquals("LongMatrix 10x10 failed transpose.", correctMatrix, matrix.transpose()); + } + + @Test + public void testDeterminant(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + assertEquals("LongMatrix 1x1 failed determinant.", 1, matrix.determinant()); + + //2x2 + matrix = new LongMatrix(grid2); + assertEquals("LongMatrix 2x2 failed determinant1.", 0, matrix.determinant()); + matrix = new LongMatrix(new long[][]{ + {1, 4}, + {4, 1} + }); + assertEquals("LongMatrix 2x2 failed determinant2.", -15, matrix.determinant()); + + //3x3 + matrix = new LongMatrix(grid3); + assertEquals("LongMatrix 3x3 failed determinant1.", 0, matrix.determinant()); + matrix = new LongMatrix(new long[][]{ + {1, 4, 2}, + {2, 4, 1}, + {4, 1, 2} + }); + assertEquals("LongMatrix 3x3 failed determinant2.", -21, matrix.determinant()); + + //4x4 + matrix = new LongMatrix(grid4); + assertEquals("LongMatrix 4x4 failed determiant1.", 0, matrix.determinant()); + matrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {2, 3, 4, 1}, + {3, 4, 1, 2}, + {4, 1, 2, 3} + }); + assertEquals("LongMatrix 4x4 failed determinant2.", 160, matrix.determinant()); + + //10x10 + matrix = new LongMatrix(grid10); + assertEquals("LongMatrix 10x10 failed determinant1.", 0, matrix.determinant()); + matrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {2, 3, 4, 5, 6, 7, 8, 9, 10, 1}, + {3, 4, 5, 6, 7, 8, 9, 10, 1, 2}, + {4, 5, 6, 7, 8, 9, 10, 1, 2, 3}, + {5, 6, 7, 8, 9, 10, 1, 2, 3, 4}, + {6, 7, 8, 9, 10, 1, 2, 3, 4, 5}, + {7, 8, 9, 10, 1, 2, 3, 4, 5, 6}, + {8, 9, 10, 1, 2, 3, 4, 5, 6, 7}, + {9, 10, 1, 2, 3, 4, 5, 6, 7, 8}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 1} + }); + assertEquals("LongMatrix 10x10 failed determinant2.", -10000000, matrix.determinant()); + } + + @Test + public void testCofactor(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix correctMatrix = new LongMatrix(grid1); + assertEquals("LongMatrix 1x1 failed cofactor.", correctMatrix, matrix.cofactor()); + + //2x2 + matrix = new LongMatrix(grid2); + correctMatrix = new LongMatrix(new long[][]{ + {2, -1}, + {-2, 1} + }); + assertEquals("LongMatrix 2x2 failed cofactor.", correctMatrix, matrix.cofactor()); + + //3x3 + matrix = new LongMatrix(grid3); + correctMatrix = new LongMatrix(3, 3, 0); + assertEquals("LongMatrix 3x3 failed cofactor1.", correctMatrix, matrix.cofactor()); + matrix = new LongMatrix(new long[][]{ + {1, 4, 2}, + {2, 4, 1}, + {4, 1, 2} + }); + correctMatrix = new LongMatrix(new long[][]{ + {7, 0, -14}, + {-6, -6, 15}, + {-4, 3, -4} + }); + assertEquals("LongMatrix 3x3 failed cofactor2.", correctMatrix, matrix.cofactor()); + + //4x4 + matrix = new LongMatrix(grid4); + correctMatrix = new LongMatrix(4, 4, 0); + assertEquals("LongMatrix 4x4 failed cofactor1.", correctMatrix, matrix.cofactor()); + matrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {2, 3, 4, 1}, + {3, 4, 1, 2}, + {4, 1, 2, 3} + }); + correctMatrix = new LongMatrix(new long[][]{ + {-36, 4, 4, 44}, + {4, 4, 44, -36}, + {4, 44, -36, 4}, + {44, -36, 4, 4} + }); + assertEquals("LongMatrix 4x4 failed cofactor2.", correctMatrix, matrix.cofactor()); + + //10x10 + //?Skipping 10x10 test because test took > 5s by itself + /* + matrix = new LongMatrix(grid10); + correctMatrix = new LongMatrix(10, 10, 0); + assertEquals("LongMatrix 10x10 failed cofactor1.", correctMatrix, matrix.cofactor()); + */ + } + + @Test + public void testPower(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix correctMatrix = new LongMatrix(new long[][]{{1}}); + assertEquals("LongMatrix 1x1 failed power.", correctMatrix, matrix.pow(3)); + + //2x2 + matrix = new LongMatrix(grid2); + correctMatrix = new LongMatrix(new long[][]{ + {9, 18}, + {9, 18} + }); + assertEquals("LongMatrix 2x2 failed power.", correctMatrix, matrix.pow(3)); + + //3x3 + matrix = new LongMatrix(grid3); + correctMatrix = new LongMatrix(new long[][]{ + {36, 72, 108}, + {36, 72, 108}, + {36, 72, 108} + }); + assertEquals("LongMatrix 3x3 failed power.", correctMatrix, matrix.pow(3)); + + //4x4 + //0 + matrix = new LongMatrix(grid4); + correctMatrix = new LongMatrix(new long[][]{ + {1, 1, 1, 1}, + {1, 1, 1, 1}, + {1, 1, 1, 1}, + {1, 1, 1, 1} + }); + assertEquals("LongMatrix 4x4 failed power 0.", correctMatrix, matrix.pow(0)); + //1 + correctMatrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4}, + {1, 2, 3, 4} + }); + assertEquals("LongMatrix 4x4 failed power 1.", correctMatrix, matrix.pow(1)); + //3 + correctMatrix = new LongMatrix(new long[][]{ + {100, 200, 300, 400}, + {100, 200, 300, 400}, + {100, 200, 300, 400}, + {100, 200, 300, 400} + }); + assertEquals("LongMatrix 4x4 failed power 3.", correctMatrix, matrix.pow(3)); + + //10x10 + matrix = new LongMatrix(grid10); + correctMatrix = new LongMatrix(new long[][]{ + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250}, + {3025, 6050, 9075, 12100, 15125, 18150, 21175, 24200, 27225, 30250} + }); + assertEquals("LongMatrix 10x10 failed power.", correctMatrix, matrix.pow(3)); + } + + @Test + public void testAdjoint(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix correctMatrix = new LongMatrix(grid1); + assertEquals("LongMatrix 1x1 failed adjoint.", correctMatrix, matrix.adjoint()); + + //2x2 + matrix = new LongMatrix(grid2); + correctMatrix = new LongMatrix(new long[][]{ + {2, -2}, + {-1, 1} + }); + assertEquals("LongMatrix 2x2 failed adjoint.", correctMatrix, matrix.adjoint()); + + //3x3 + matrix = new LongMatrix(grid3); + correctMatrix = new LongMatrix(3, 3, 0); + assertEquals("LongMatrix 3x3 failed adjoint.", correctMatrix, matrix.adjoint()); + + //4x4 + matrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {2, 3, 4, 1}, + {3, 4, 1, 2}, + {4, 1, 2, 3} + }); + correctMatrix = new LongMatrix(new long[][]{ + {-36, 4, 4, 44}, + {4, 4, 44, -36}, + {4, 44, -36, 4}, + {44, -36, 4, 4} + }); + assertEquals("LongMatrix 4x4 failed adjoint.", correctMatrix, matrix.adjoint()); + + //10x10 + //?Skipping 10x10 test because test took > 5s by itself + /* + matrix = new LongMatrix(grid10); + correctMatrix = new LongMatrix(10, 10, 0); + assertEquals("LongMatrix 10x10 failed adjoint.", correctMatrix, matrix.adjoint()); + */ + } + + @Test + public void testInverse(){ + //1x1 + LongMatrix matrix = new LongMatrix(grid1); + LongMatrix correctMatrix = new LongMatrix(grid1); + assertEquals("LongMatrix 1x1 failed inverse.", correctMatrix, matrix.inverse()); + + //2x2 + matrix = new LongMatrix(new long[][]{ + {1, 4}, + {4, 1} + }); + correctMatrix = new LongMatrix(new long[][]{ + {-0, 0}, + {0, -0} + }); + assertEquals("LongMatrix 2x2 failed inverse.", correctMatrix, matrix.inverse()); + + //3x3 + matrix = new LongMatrix(new long[][]{ + {1, 4, 2}, + {2, 4, 1}, + {4, 1, 2} + }); + correctMatrix = new LongMatrix(new long[][]{ + {-0, 0, 0}, + {0, 0, -0}, + {0, -0, 0} + }); + assertEquals("LongMatrix 3x3 failed inverse.", correctMatrix, matrix.inverse()); + + //4x4 + matrix = new LongMatrix(new long[][]{ + {1, 2, 3, 4}, + {2, 3, 4, 1}, + {3, 4, 1, 2}, + {4, 1, 2, 3} + }); + correctMatrix = new LongMatrix(new long[][]{ + {-0, 0, 0, 0}, + {0, 0, 0, -0}, + {0, 0, -0, 0}, + {0, -0, 0, 0} + }); + assertEquals("LongMatrix 4x4 failed inverse.", correctMatrix, matrix.inverse()); + + //10x10 + //?Skipped 10x10 because it would take a long time to compute + } +}