@Test public void moreOpsTest() { double[][] basicArray = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}; Matrix m = new Matrix(basicArray); /** MINOR ARRAY (2, 2) */ double[][] minorArr = {{1, 3}, {7, 9}, {10, 12}}; assertTrue(m.minor(2, 2).equals(new Matrix(minorArr))); /** DETERMINANT AND INVERSE */ double[][] basicSquare = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Matrix basicSquareMatrix = new Matrix(basicSquare); assertTrue(basicSquareMatrix.det() == 0); assertFalse(basicSquareMatrix.invertible()); // since det = 0; double[][] invertibleArr = {{7, 2, 1}, {0, 3, -1}, {-3, 4, -2}}; Matrix invertibleMatrix = new Matrix(invertibleArr); double[][] inverse = {{-2, 8, -5}, {3, -11, 7}, {9, -34, 21}}; assertTrue(invertibleMatrix.inverse().equals(new Matrix(inverse))); /** ECHELON FORM */ double[][] echelonRes1 = {{1, 2, 0}, {0, 1, 1.25}, {0, 0, 1}}; Matrix echelonMatrix1 = new Matrix(echelonRes1); double[][] testArr = {{1, 2, 0}, {0, 4, 5}, {3, 2, 6}}; Matrix testMatrix = new Matrix(testArr); testMatrix.echelonForm(); double[][] testArr2 = {{0, 4, 5}, {1, 2, 0}, {3, 2, 6}}; Matrix testMatrix2 = new Matrix(testArr2); testMatrix2.echelonForm(); assertTrue(testMatrix.equals(echelonMatrix1)); assertTrue(testMatrix2.equals(echelonMatrix1)); double[][] identityArr = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; Matrix identityMatrix = new Matrix(identityArr); testMatrix.reducedEchelonForm(); assertTrue(testMatrix.equals(identityMatrix)); double[][] moreRows = {{4, 5}, {2, 1}, {0, 0}}; Matrix moreRowsMatrix = new Matrix(moreRows); double[][] goodMoreRows = {{1, 0}, {0, 1}, {0, 0}}; Matrix goodMoreRowsMatrix = new Matrix(goodMoreRows); moreRowsMatrix.reducedEchelonForm(); assertTrue(moreRowsMatrix.equals(goodMoreRowsMatrix)); double[][] moreCols = {{2, 4, 8}, {1, 2, 9}}; Matrix moreColsMatrix = new Matrix(moreCols); double[][] goodMoreCols = {{1, 2, 0}, {0, 0, 1}}; Matrix goodMoreColsMatrix = new Matrix(goodMoreCols); moreColsMatrix.reducedEchelonForm(); assertTrue(moreColsMatrix.equals(goodMoreColsMatrix)); /** PIVOT COUNT */ assertTrue(moreColsMatrix.pivots() == 2); assertTrue(moreRowsMatrix.pivots() == 2); assertTrue(testMatrix.pivots() == 3); }