diff --git a/src/main/java/com/mattrixwv/matrix/LongMatrix.java b/src/main/java/com/mattrixwv/matrix/LongMatrix.java new file mode 100644 index 0000000..82138b1 --- /dev/null +++ b/src/main/java/com/mattrixwv/matrix/LongMatrix.java @@ -0,0 +1,782 @@ +//Matrix/src/main/java/com/mattrixwv/matrix/LongMatrix.java +//Mattrixwv +// Created: 02-10-22 +//Modified: 02-10-22 +package com.mattrixwv.matrix; + + +import java.util.StringJoiner; + +import com.mattrixwv.matrix.exceptions.InvalidCoordinatesException; +import com.mattrixwv.matrix.exceptions.InvalidGeometryException; +import com.mattrixwv.matrix.exceptions.InvalidRowSizeException; +import com.mattrixwv.matrix.exceptions.InvalidScalarException; + + +public class LongMatrix{ + protected long[][] grid; + + //Helper functions + protected void setGrid(long[][] grid){ + if(grid.length == 0){ + this.grid = new long[0][0]; + } + else if(grid[0].length == 0){ + this.grid = new long[grid.length][0]; + } + else{ + //Make sure all rows are the same length + int length = grid[0].length; + for(int cnt = 1;cnt < grid.length;++cnt){ + if(grid[cnt].length != length){ + throw new InvalidRowSizeException("All rows in a matrix must be the same size"); + } + } + + //Copy every element over to a new grid + long[][] newGrid = new long[grid.length][grid[0].length]; + for(int rowCnt = 0;rowCnt < grid.length;++rowCnt){ + for(int colCnt = 0;colCnt < grid[0].length;++colCnt){ + newGrid[rowCnt][colCnt] = grid[rowCnt][colCnt]; + } + } + + //Save the new grid + this.grid = newGrid; + } + } + protected long[][] copyGrid(){ + //Allocate memory for the new grid + long[][] newGrid = new long[grid.length][grid[0].length]; + + //Copy every element from the current grid to the new one + for(int row = 0;row < grid.length;++row){ + for(int col = 0;col < grid[0].length;++col){ + newGrid[row][col] = grid[row][col]; + } + } + + //Return the new grid + return newGrid; + } + protected boolean isSquare(){ + if(getNumRows() == 0){ + return false; + } + else{ + return getNumRows() == getNumCols(); + } + } + //Returns a matrix with the supplied row and column removed + protected LongMatrix laplaceExpansionHelper(int row, int col){ + //Make sure the matrix is square + if(!isSquare()){ + throw new InvalidGeometryException("A matrix must be square for you to perform Laplace Expansion"); + } + //Make sure the matrix is large enough to have this operation performed + if((getNumRows() <= 1) || (getNumCols() <= 1)){ + throw new InvalidGeometryException("A matrix must be at least 2x2 for you to perform Laplace Expansion: " + getNumRows() + "x" + getNumCols()); + } + //Make sure the row is valid + if((row < 0) || (row >= getNumRows())){ + throw new InvalidCoordinatesException("An invalid row number was supplied: " + row + ". The matrix contains " + getNumRows() + " rows"); + } + //Make sure the col is valid + if((col < 0) || (col >= getNumCols())){ + throw new InvalidCoordinatesException("An invalid column number was supplied: " + col + ". The matrix contains " + getNumCols() + " columns"); + } + + + //Create a new matrix that is one row and column smaller than the existing row + long[][] newGrid = new long[getNumRows() - 1][getNumCols() - 1]; + //Traverse the matrix and set the values in the new matrix, skipping elements in the given row and col + for(int workingRow = 0, newRow = 0;workingRow < getNumRows();++workingRow){ + //Skip the row we are expanding + if(workingRow == row){ + continue; + } + for(int workingCol = 0, newCol = 0;workingCol < getNumCols();++workingCol){ + //Skip the column we are expanding + if(workingCol == col){ + continue; + } + newGrid[newRow][newCol] = grid[workingRow][workingCol]; + ++newCol; + } + ++newRow; + } + + + //Return the new matrix + return new LongMatrix(newGrid); + } + + //Constructors + public LongMatrix(){ + grid = new long[0][0]; + } + public LongMatrix(long[][] grid){ + setGrid(grid); + } + public LongMatrix(LongMatrix matrix){ + setGrid(matrix.grid); + } + public LongMatrix(int rows, int cols, long fill){ + if(rows <= 0){ + throw new InvalidGeometryException("A filled matrix must have at least 1 row"); + } + else if(cols <= 0){ + throw new InvalidGeometryException("A filled matrix must have at least 1 column"); + } + else{ + grid = new long[rows][cols]; + for(int row = 0;row < rows;++row){ + for(int col = 0;col < cols;++col){ + grid[row][col] = fill; + } + } + } + } + + //Gets + public long get(int row, int col){ + //Make sure the row and column are valid + if(row >= grid.length){ + throw new InvalidCoordinatesException("Row cannot be greater than the number of rows"); + } + else if(col >= grid[0].length){ + throw new InvalidCoordinatesException("Column cannot be greater than the number of columns"); + } + + //Return the location in the grid + return grid[row][col]; + } + public LongMatrix getRow(int row){ + //Make sure the row number is valid + if((row < 0) || (row >= grid.length)){ + throw new InvalidCoordinatesException("The row number " + row + " is not valid"); + } + + //Generate a copy of the row + long[][] newRow = new long[1][grid[row].length]; + for(int col = 0;col < grid[row].length;++col){ + newRow[0][col] = grid[row][col]; + } + + //Return the new matrix + return new LongMatrix(newRow); + } + public int getNumRows(){ + if(grid == null){ + return 0; + } + else{ + return grid.length; + } + } + public LongMatrix getCol(int col){ + //Make sure the column number is valid + if((col < 0) || (grid.length == 0) || (col > grid[0].length)){ + throw new InvalidCoordinatesException("The column number " + col + " is not valid"); + } + + //Generate a copy of the col + long[][] newColumn = new long[grid.length][1]; + for(int row = 0;row < grid.length;++row){ + newColumn[row][0] = grid[row][col]; + } + + //Return the new matrix + return new LongMatrix(newColumn); + } + public int getNumCols(){ + if(grid.length > 0){ + return grid[0].length; + } + else{ + return 0; + } + } + //Sets + public void set(int row, int col, long value){ + //Make sure the row number is valid + if((row < 0) || (row >= grid.length)){ + throw new InvalidCoordinatesException("Invalid row number " + row); + } + //Make sure the column number is valid + if((col < 0) || (col >= getNumCols())){ + throw new InvalidCoordinatesException("Invalid column number " + col); + } + + //Save the element + grid[row][col] = value; + } + public void setRow(int row, long[] elements){ + //Make sure the row number is valid + if((row < 0) || (row >= grid.length)){ + throw new InvalidCoordinatesException("Invalid row number " + row); + } + //Make sure the number of elements is valid + if(elements.length != getNumCols()){ + throw new InvalidGeometryException("Invalid number of elements " + elements.length + " must be " + getNumCols()); + } + + //Save the elements + for(int col = 0;col < elements.length;++col){ + grid[row][col] = elements[col]; + } + } + public void setRow(int row, LongMatrix matrix){ + //Make sure the matrix has a single row + if(matrix.getNumRows() != 1){ + throw new InvalidGeometryException("Setting a row by Matrix requires the matrix contain a single row"); + } + + //Set the row + setRow(row, matrix.grid[0]); + } + public void setCol(int col, long[] elements){ + //Make sure the column number is valid + if((col < 0) || (col >= getNumCols())){ + throw new InvalidCoordinatesException("Invalid column number " + col); + } + //Make sure the number of elements is valid + if(elements.length != grid.length){ + throw new InvalidCoordinatesException("Invalid number of elements " + elements.length + " must be " + grid.length); + } + + //Save the elements + for(int row = 0;row < elements.length;++row){ + grid[row][col] = elements[row]; + } + } + public void setCol(int col, LongMatrix matrix){ + //Make sure the matrix has a single column + if(matrix.getNumCols() != 1){ + throw new InvalidGeometryException("Setting a column by Matrix requires the matrix contain a single column"); + } + + //Set the column + setCol(col, matrix.getCol(0)); + } + //Adds + public void addRow(long[] elements){ + //Make sure the number of columns is valid + if((grid.length == 0) || (getNumCols() == elements.length)){ + long[][] newGrid = new long[grid.length + 1][elements.length]; + //Copy all existing data into the new grid + for(int row = 0;row < grid.length;++row){ + newGrid[row] = grid[row]; + } + grid = newGrid; + } + else{ + throw new InvalidGeometryException("Invalid number of elements " + elements.length + " must be " + getNumCols()); + } + + //Add all elements to the grid + for(int col = 0;col < elements.length;++col){ + grid[grid.length - 1][col] = elements[col]; + } + } + public void addRow(LongMatrix matrix){ + //Make sure the matrix has a single row + if(matrix.getNumRows() != 1){ + throw new InvalidGeometryException("Adding a row by Matrix requires the matrix contain a single row"); + } + + //Add the row + addRow(matrix.grid[0]); + } + public void addCol(long[] elements){ + //Make sure the number of rows is valid + if(grid.length == 0){ + grid = new long[1][elements.length]; + } + else if(grid.length == elements.length){ + //Copy all existing data into the new grid + for(int row = 0;row < grid.length;++row){ + long[] workingRow = new long[grid[row].length + 1]; + for(int workingCol = 0;workingCol < grid[row].length;++workingCol){ + workingRow[workingCol] = grid[row][workingCol]; + } + grid[row] = workingRow; + } + } + else{ + throw new InvalidGeometryException("Invalid number of elements " + elements.length + " must be " + getNumCols()); + } + + //Add all elements to the grid + for(int row = 0;row < elements.length;++row){ + grid[row][grid[row].length - 1] = elements[row]; + } + } + public void addCol(LongMatrix matrix){ + //Make sure the matrix has a single column + if(matrix.getNumCols() != 1){ + throw new InvalidGeometryException("Adding a column by Matrix requires the matrix contain a single column"); + } + + //Add the column + addCol(matrix.getCol(0)); + } + public LongMatrix appendRight(LongMatrix rightSide){ + //Make sure the matrices have the same number of rows + if(getNumRows() != rightSide.getNumRows()){ + throw new InvalidGeometryException("Invalid number of rows. " + rightSide.getNumRows() + " must be " + getNumRows()); + } + + //Traverse both matrices and set their values in the new matrix + long[][] newGrid = new long[getNumRows()][getNumCols() + rightSide.getNumCols()]; + for(int row = 0;row < getNumRows();++row){ + //Set all elements from the current grid's row + for(int col = 0;col < getNumCols();++col){ + newGrid[row][col] = grid[row][col]; + } + //Set all elements from the right side grid's row + for(int col = 0;col < rightSide.getNumCols();++col){ + newGrid[row][getNumCols() + col] = rightSide.grid[row][col]; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix appendBottom(LongMatrix rightSide){ + //Make sure the matrices have the same number of columns + if(getNumCols() != rightSide.getNumCols()){ + throw new InvalidGeometryException("Invalid number of columns. " + rightSide.getNumCols() + " must be " + getNumCols()); + } + + //Traverse both matrices and set their values in the new matrix + long[][] newGrid = new long[getNumRows() + rightSide.getNumRows()][getNumCols()]; + for(int col = 0;col < getNumCols();++col){ + //Set all elements from the current grid's column + for(int row = 0;row < getNumRows();++row){ + newGrid[row][col] = grid[row][col]; + } + //Set all elements from the right side grid's column + for(int row = 0;row < rightSide.getNumRows();++row){ + newGrid[getNumRows() + row][col] = rightSide.grid[row][col]; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + + //Simple operations + public static LongMatrix generateIdentity(int size){ + //Make sure the size is valid + if(size > 0){ + //Create a grid with the correct size + long[][] newGrid = new long[size][size]; + + //Go through every element and make sure it is set correctly + for(int row = 0;row < size;++row){ + for(int col = 0;col < size;++col){ + if(col == row){ + newGrid[row][col] = 1; + } + else{ + newGrid[row][col] = 0; + } + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + else{ + throw new InvalidGeometryException("An identity matrix must have a size > 0"); + } + } + public LongMatrix add(LongMatrix rightSide){ + //Make sure the matrices have compatable geometry + if((getNumRows() != rightSide.getNumRows()) || (getNumCols() != rightSide.getNumCols())){ + throw new InvalidGeometryException("Both matrices must have the same number of rows and columns: " + getNumRows() + "x" + getNumCols() + " + " + rightSide.getNumRows() + "x" + rightSide.getNumCols()); + } + + //Create a new grid with the same elements as the current grid + long[][] newGrid = copyGrid(); + + //Add each element in the righ tmatrix to the corresponding element in the left matrix + for(int row = 0;row < newGrid.length;++row){ + for(int col = 0;col < newGrid[0].length;++col){ + newGrid[row][col] += rightSide.grid[row][col]; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix add(long scalar){ + //Create a new grid with the same elements as the current grid + long[][] newGrid = copyGrid(); + + //Add the scalar to each element in the grid + for(int row = 0;row < newGrid.length;++row){ + for(int col = 0;col < newGrid[0].length;++col){ + newGrid[row][col] += scalar; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix subtract(LongMatrix rightSide){ + //Make sure the matrices have compatable geometry + if((getNumRows() != rightSide.getNumRows()) || (getNumCols() != rightSide.getNumCols())){ + throw new InvalidGeometryException("Both matrices must have the same number of rows and columsn: " + getNumRows() + "x" + getNumCols() + " + " + rightSide.getNumRows() + "x" + rightSide.getNumCols()); + } + + //Create a new grid with the same elements as the current gird + long[][] newGrid = copyGrid(); + + //Subtract each element in the righ tmatrix from the corresponding element in the left matrix + for(int row = 0;row < newGrid.length;++row){ + for(int col = 0;col < newGrid[0].length;++col){ + newGrid[row][col] -= grid[row][col]; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix subtract(long scalar){ + //Create a new grid with the same elements as the current grid + long[][] newGrid = copyGrid(); + + //Subtract the scalar from each element in the grid + for(int row = 0;row < newGrid.length;++row){ + for(int col = 0;col < newGrid[0].length;++col){ + newGrid[row][col] -= scalar; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix multiply(LongMatrix rightSide){ + //Make sure the matrices have compatable geometry + if(getNumCols() != rightSide.getNumRows()){ + throw new InvalidGeometryException("The left matrix must have the same number of columns as the right matrix has rows: " + getNumRows() + "x" + getNumCols() + " + " + rightSide.getNumRows() + "x" + rightSide.getNumCols()); + } + + //Create a new grid with the same elements as the current grid + long[][] newGrid = new long[getNumRows()][rightSide.getNumCols()]; + + //Multiply each row in the left matrix with each column int he right matrix to come up with the current element + for(int leftRow = 0;leftRow < grid.length;++leftRow){ + for(int rightCol = 0;rightCol < rightSide.getNumCols();++rightCol){ + //Get a sum of the product of each column in the current row (left) and each row in the current column (right) + int elementProductSum = 0; + for(int incrementCounter = 0;incrementCounter < grid.length;++incrementCounter){ + elementProductSum += grid[leftRow][incrementCounter] * rightSide.grid[incrementCounter][rightCol]; + } + newGrid[leftRow][rightCol] = elementProductSum; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix multiply(long scalar){ + //Create a new grid with the same elements as the current grid + long[][] newGrid = copyGrid(); + + //Multiply every element in the grid by the scalar + for(int row = 0;row < grid.length;++row){ + for(int col = 0;col < grid[0].length;++col){ + newGrid[row][col] *= scalar; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix pow(long power){ + //Make sure the matrix is square so it can be multiplied + if(!isSquare()){ + throw new InvalidGeometryException("The matrix must be square to raise it to a power"); + } + //Make sure the power is positive + if(power < 0){ + throw new InvalidScalarException("The power must be >= 0"); + } + else if(power == 0){ + return new LongMatrix(getNumRows(), getNumCols(), 1); + } + + //Create a new matrix for the product + LongMatrix newMatrix = clone(); + //Multiply the current grid power times + for(int currentPower = 1;currentPower < power;++currentPower){ + newMatrix = newMatrix.multiply(this); + } + + //Return the new grid + return newMatrix; + } + public long dotProduct(LongMatrix rightSide){ + //Make sure the matrices have compatable geometry + if(getNumCols() != rightSide.getNumRows()){ + throw new InvalidGeometryException("The left matrix must have the same number of columns as the right matrix has rows: " + getNumRows() + "x" + getNumCols() + " + " + rightSide.getNumRows() + "x" + rightSide.getNumCols()); + } + + //Multiply each row in the left matrix with each column in the right matrix to come up with the current element + //?Would be simpler, but slower, to get the product matrix to come up with the current element + long sum = 0; + for(int leftRow = 0;leftRow < grid.length;++leftRow){ + for(int rightCol = 0;rightCol < rightSide.getNumCols();++rightCol){ + for(int incrementCounter = 0;incrementCounter < grid.length;++incrementCounter){ + sum += grid[leftRow][incrementCounter] * rightSide.grid[incrementCounter][rightCol]; + } + } + } + + //Return the sum + return sum; + } + public LongMatrix hadamardProduct(LongMatrix rightSide){ + //Make sure the matrices have compatable geometry + if((getNumRows() != rightSide.getNumRows()) || (getNumCols() != rightSide.getNumCols())){ + throw new InvalidGeometryException("Both matrices must have the same number of rows and columns: " + getNumRows() + "x" + getNumCols() + " + " + rightSide.getNumRows() + "x" + rightSide.getNumCols()); + } + + //Create a new grid with the same element as the current grid + long[][] newGrid = copyGrid(); + + //Multiply each element in the right matrix to the corresponding element in the left matrix + for(int row = 0;row < newGrid.length;++row){ + for(int col = 0;col < newGrid[0].length;++col){ + newGrid[row][col] *= rightSide.grid[row][col]; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + + //Complex operations + public LongMatrix transpose(){ + //Create a new grid + long[][] newGrid = new long[getNumCols()][getNumRows()]; + + //Traverse every element in the existing grid and add each column to the new grid as a row + for(int col = 0;col < getNumCols();++col){ + for(int row = 0;row < getNumRows();++row){ + newGrid[col][row] = grid[row][col]; + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public long det(){ + return determinant(); + } + public long determinant(){ + //Make sure the matrix is square + if(!isSquare()){ + throw new InvalidGeometryException("A matrix must be square for it to have a determinant"); + } + //?Don't have to worry about a matrix existing. isSquare takes care of 0x0 matrix + + //Determine the formula do use for the determinant + long det = 0; + switch(getNumRows()){ + //If the matrix is 1x1 return the number + case 1 : det = grid[0][0]; break; + //If the matrix is 2x2 use the formula + case 2 : { + det = (grid[0][0] * grid[1][1]) - (grid[0][1] * grid[1][0]); + } + break; + //If the matrix is 3x3 use the formula + case 3 : { + det = (grid[0][0] * grid[1][1] * grid[2][2]) + (grid[0][1] * grid[1][2] * grid[2][0]) + (grid[0][2] * grid[1][0] * grid[2][1]) - + (grid[2][0] * grid[1][1] * grid[0][2]) - (grid[2][1] * grid[1][2] * grid[0][0]) - (grid[2][2] * grid[1][0] * grid[0][1]); + } + break; + //If the matrix is larger break it down and try again + default : { + //Find the row/column with the largest number of 0's + int zerosLocation = 0; + int maxNumZeros = 0; + boolean zerosRow = true; + //Check the rows + for(int row = 0;row < getNumRows();++row){ + int numZeros = 0; + for(int col = 0;col < getNumCols();++col){ + if(grid[row][col] == 0){ + ++numZeros; + } + } + if(numZeros > maxNumZeros){ + maxNumZeros = numZeros; + zerosLocation = row; + zerosRow = true; + } + } + //Check the columns + for(int col = 0;col < getNumCols();++col){ + int numZeros = 0; + for(int row = 0;row < getNumRows();++row){ + if(grid[row][col] == 0){ + ++numZeros; + } + } + if(numZeros > maxNumZeros){ + maxNumZeros = numZeros; + zerosLocation = col; + zerosRow = false; + } + } + + //If the largest number of zeros were found in a row + if(zerosRow){ + //Set a variable to make sure the appropriate + or - is applied to the scalar + int multiplier = 1; + if((zerosLocation % 2) == 1){ + multiplier = -1; + } + //Go through every column in the optimal row using the formula + for(int col = 0;col < getNumCols();++col){ + if(grid[zerosLocation][col] != 0){ + det += (multiplier * grid[zerosLocation][col] * laplaceExpansionHelper(zerosLocation, col).determinant()); + } + multiplier = -multiplier; + } + } + //If the largest number of zeros were found in a column + else{ + //Set a variable to make sure the appropriate + or - is applied to the scalar + int multiplier = 1; + if((zerosLocation % 2) == 1){ + multiplier = -1; + } + //Go through every row in the coptimal column using the formula + for(int row = 0;row < getNumRows();++row){ + if(grid[row][zerosLocation] != 0){ + det += (multiplier * grid[row][zerosLocation] * laplaceExpansionHelper(row, zerosLocation).determinant()); + } + multiplier = -multiplier; + } + } + } + } + + //Return the determinant + return det; + } + public LongMatrix cof(){ + return cofactor(); + } + public LongMatrix cofactor(){ + //Make sure the matrix is square + if(!isSquare()){ + throw new InvalidGeometryException("A matrix must be square to find the cofactor matrix"); + } + + //Create a new grid + long[][] newGrid = new long[getNumRows()][getNumCols()]; + //If the grid is 1x1 return the grid + if(getNumRows() == 1){ + newGrid[0][0] = 1; + } + //Use the formula to find the cofactor matrix + else{ + for(int row = 0;row < getNumRows();++row){ + int multiplier = ((row % 2) == 0) ? 1 : -1; + for(int col = 0;col < getNumCols();++col){ + newGrid[row][col] = multiplier * laplaceExpansionHelper(row, col).determinant(); + multiplier = -multiplier; + } + } + } + + //Return the new matrix + return new LongMatrix(newGrid); + } + public LongMatrix adj(){ + return adjoint(); + } + public LongMatrix adjoint(){ + return cofactor().transpose(); + } + public LongMatrix inverse(){ + //Make sure the matrix is square + if(!isSquare()){ + throw new InvalidGeometryException("A matrix must be square for it to have an inverse"); + } + + //Make sure the determinant is not 0 + long determinant = determinant(); + if(determinant == 0){ + throw new InvalidScalarException("The determinant cannot be 0"); + } + + //Return the new matrix + return adjoint().multiply(1 / determinant); + } + + //Object funtions + @Override + public boolean equals(Object rightSide){ + if(rightSide.getClass().equals(this.getClass())){ + LongMatrix rightMatrix = (LongMatrix)rightSide; + + //Make sure they have the same number of elements + if(getNumRows() != rightMatrix.getNumRows()){ + return false; + } + else if(getNumCols() != rightMatrix.getNumCols()){ + return false; + } + + //Check every element + for(int row = 0;row < getNumRows();++row){ + for(int col = 0;col < getNumCols();++col){ + if(grid[row][col] != rightMatrix.grid[row][col]){ + return false; + } + } + } + + //If false hasn't been returned yet then they are equal + return true; + } + else if(rightSide.getClass().equals(long[][].class)){ + long[][] rightMatrix = (long[][])rightSide; + + return equals(new LongMatrix(rightMatrix)); + } + else{ + return false; + } + } + @Override + public int hashCode(){ + return grid.hashCode(); + } + @Override + public String toString(){ + StringJoiner matrix = new StringJoiner("\n"); + for(int rowCnt = 0;rowCnt < getNumRows();++rowCnt){ + StringJoiner row = new StringJoiner(",", "[", "]"); + + for(int colCnt = 0;colCnt < getNumCols();++colCnt){ + row.add(Long.toString(grid[rowCnt][colCnt])); + } + + matrix.add(row.toString()); + } + return matrix.toString(); + } + @Override + public LongMatrix clone(){ + return new LongMatrix(grid); + } +} diff --git a/src/test/java/com/mattrixwv/matrix/TestBigIntegerMatrix.java b/src/test/java/com/mattrixwv/matrix/TestBigIntegerMatrix.java new file mode 100644 index 0000000..82189b8 --- /dev/null +++ b/src/test/java/com/mattrixwv/matrix/TestBigIntegerMatrix.java @@ -0,0 +1,1313 @@ +//Matrix/src/test/java/com/mattrixwv/matrix/TestBigBigIntegerMatrix.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 java.math.BigInteger; + +import org.junit.Test; + + +public class TestBigIntegerMatrix{ + //Grid 1x1 + private static final BigInteger[][] grid1 = { + {BigInteger.ONE} + }; + private static final BigInteger[][] transformGrid1_1 = { + {BigInteger.ONE} + }; + private static final BigInteger[][] transformGrid1_2 = { + {BigInteger.TWO} + }; + + //Grid 2x2 + private static final BigInteger[][] grid2 = { + {BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO} + }; + private static final BigInteger[][] transformGrid2_1 = { + {BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.ONE, BigInteger.ZERO} + }; + private static final BigInteger[][] transformGrid2_2 = { + {BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.TWO, BigInteger.valueOf(3)} + }; + + //Grid 3x3 + private static final BigInteger[][] grid3 = { + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }; + private static final BigInteger[][] transformGrid3_1 = { + {BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO} + }; + private static final BigInteger[][] transformGrid3_2 = { + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }; + + //Grid 4x4 + private static final BigInteger[][] grid4 = { + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }; + private static final BigInteger[][] transformGrid4_1 = { + {BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO} + }; + private static final BigInteger[][] transformGrid4_2 = { + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)} + }; + + //Grid 10x10 + private static final BigInteger[][] grid10 = { + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)} + }; + private static final BigInteger[][] transformGrid10_1 = { + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO}, + {BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE, BigInteger.ZERO} + }; + private static final BigInteger[][] transformGrid10_2 = { + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)} + }; + + + @Test + public void testEquals(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + assertTrue("BigIntegerMatrix 1x1 failed equals BigIntegerMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals = matrix.equals(grid1); + assertTrue("BigIntegerMatrix 1x1 failed equals BigInteger[][].", gridEquals); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + assertTrue("BigIntegerMatrix 2x2 failed equals BigIntegerMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals2 = matrix.equals(grid2); + assertTrue("BigIntegerMatrix 2x2 failed equals BigInteger[][].", gridEquals2); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + assertTrue("BigIntegerMatrix 3x3 failed equals BigIntegerMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals3 = matrix.equals(grid3); + assertTrue("BigIntegerMatrix 3x3 failed equals BigInteger[][].", gridEquals3); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + assertTrue("BigIntegerMatrix 4x4 failed equals BigIntegerMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals4 = matrix.equals(grid4); + assertTrue("BigIntegerMatrix 4x4 failed equals BigInteger[][].", gridEquals4); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + assertTrue("BigIntegerMatrix = 10x10 failed equals BigIntegerMatrix.", matrix.equals(matrix)); + @SuppressWarnings("unlikely-arg-type") + boolean gridEquals10 = matrix.equals(grid10); + assertTrue("BigIntegerMatrix 10x10 failed equals BigInteger[][].", gridEquals10); + } + + @Test + public void testGets(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + assertEquals("BigIntegerMatrix 1x1 failed get.", BigInteger.ONE, matrix.get(0, 0)); + //GetRow + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed getCol.", correctMatrix, matrix.getCol(0)); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + assertEquals("BigIntegerMatrix 2x2 failed get.", BigInteger.ONE, matrix.get(0, 0)); + //GetRow + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE, BigInteger.TWO}}); + assertEquals("BigIntegerMatrix 2x2 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE}, + {BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 2x2 failed getCol.", correctMatrix, matrix.getCol(0)); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + assertEquals("BigIntegerMatrix 3x3 failed get.", BigInteger.ONE, matrix.get(0, 0)); + //GetRow + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}}); + assertEquals("BigIntegerMatrix 3x3 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 3x3 failed getCol.", correctMatrix, matrix.getCol(0)); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + assertEquals("BigIntegerMatrix 4x4 failed get.", BigInteger.ONE, matrix.get(0, 0)); + //GetRow + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}}); + assertEquals("BigIntegerMatrix 4x4 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 4x4 failed getCol.", correctMatrix, matrix.getCol(0)); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + assertEquals("BigIntegerMatrix 10x10 failed get.", BigInteger.ONE, matrix.get(0, 0)); + //GetRow + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}}); + assertEquals("BigIntegerMatrix 10x10 failed getRow.", correctMatrix, matrix.getRow(0)); + //GetColumn + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE}, + {BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 10x10 failed getColumn.", correctMatrix, matrix.getCol(0)); + } + + @Test + public void testSets(){ + //1x1 + //Set + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + matrix.set(0, 0, BigInteger.TWO); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.TWO}}); + assertEquals("BigIntegerMatrix 1x1 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new BigInteger[]{BigInteger.ZERO}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ZERO}}); + assertEquals("BigIntegerMatrix 1x1 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new BigInteger[]{BigInteger.ONE}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed setCol.", correctMatrix, matrix); + + //2x2 + //Set + matrix = new BigIntegerMatrix(grid2); + matrix.set(0, 0, BigInteger.valueOf(3)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3), BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 2x2 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(1, new BigInteger[]{BigInteger.TWO, BigInteger.ONE}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3), BigInteger.TWO}, + {BigInteger.TWO, BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 2x2 failed set row.", correctMatrix, matrix); + //SetColumn + matrix = new BigIntegerMatrix(grid2); + matrix.setCol(0, new BigInteger[]{BigInteger.valueOf(3), BigInteger.valueOf(3)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3), BigInteger.TWO}, + {BigInteger.valueOf(3), BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 2x2 failed set row.", correctMatrix, matrix); + + //3x3 + //Set + matrix = new BigIntegerMatrix(grid3); + matrix.set(0, 0, BigInteger.valueOf(3)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3), BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + }); + assertEquals("BigIntegerMatrix 3x3 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new BigInteger[]{BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 3x3 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new BigInteger[]{BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 3x3 failed setColumn.", correctMatrix, matrix); + + //4x4 + //Set + matrix = new BigIntegerMatrix(grid4); + matrix.set(0, 0, BigInteger.valueOf(3)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3), BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed set.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new BigInteger[]{BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new BigInteger[]{BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed setCol.", correctMatrix, matrix); + + //10x10 + //Set + matrix = new BigIntegerMatrix(grid10); + matrix.set(0, 0, BigInteger.valueOf(3)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3), BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)} + }); + assertEquals("BigIntegerMatrix 10x10 failed setRow.", correctMatrix, matrix); + //SetRow + matrix.setRow(0, new BigInteger[]{BigInteger.valueOf(10), BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(10), BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)} + }); + assertEquals("BigIntegerMatrix 10x10 failed setRow.", correctMatrix, matrix); + //SetColumn + matrix.setCol(0, new BigInteger[]{BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.valueOf(9), BigInteger.valueOf(8), BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(5), BigInteger.valueOf(4), BigInteger.valueOf(3), BigInteger.TWO, BigInteger.ONE}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ZERO, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)} + }); + assertEquals("BigIntegerMatrix 10x10 failed setColumn.", correctMatrix, matrix); + } + + @Test + public void testAdds(){ + //1x1 + //AddRow + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + matrix.addRow(new BigInteger[]{BigInteger.ONE}); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE}, {BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new BigIntegerMatrix(grid1); + matrix.addCol(new BigInteger[]{BigInteger.ONE}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE, BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed addCol.", correctMatrix, matrix); + + //2x2 + //AddRow + matrix = new BigIntegerMatrix(grid2); + matrix.addRow(new BigInteger[]{BigInteger.ONE, BigInteger.TWO}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 2x2 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new BigIntegerMatrix(grid2); + matrix.addCol(new BigInteger[]{BigInteger.valueOf(3), BigInteger.valueOf(3)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 2x2 failed addCol.", correctMatrix, matrix); + + //3x3 + //AddRow + matrix = new BigIntegerMatrix(grid3); + matrix.addRow(new BigInteger[]{BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 3x3 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new BigIntegerMatrix(grid3); + matrix.addCol(new BigInteger[]{BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 3x3 failed addCol.", correctMatrix, matrix); + + //4x4 + //AddRow + matrix = new BigIntegerMatrix(grid4); + matrix.addRow(new BigInteger[]{BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix.addCol(new BigInteger[]{BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)} + }); + assertEquals("BigIntegerMatrix 4x4 failed addCol.", correctMatrix, matrix); + + //10x10 + //AddRow + matrix = new BigIntegerMatrix(grid10); + matrix.addRow(new BigInteger[]{BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)} + }); + assertEquals("BigIntegerMatrix 10x10 failed addRow.", correctMatrix, matrix); + //AddColumn + matrix = new BigIntegerMatrix(grid10); + matrix.addCol(new BigInteger[]{BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11), BigInteger.valueOf(11)}); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)} + }); + assertEquals("BigIntegerMatrix 10x10 failed addColumn.", correctMatrix, matrix); + } + + @Test + public void testAppends(){ + //1x1 + //appendRight + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix secondMatrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE, BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE}, + {BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 1x1 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //2x2 + //appendRight + matrix = new BigIntegerMatrix(grid2); + secondMatrix = new BigIntegerMatrix(grid2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.ONE, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 2x2 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ONE, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 2x2 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //3x3 + //appendRight + matrix = new BigIntegerMatrix(grid3); + secondMatrix = new BigIntegerMatrix(grid3); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 3x3 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 3x3 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //4x4 + //appendRight + matrix = new BigIntegerMatrix(grid4); + secondMatrix = new BigIntegerMatrix(grid4); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + + //10x10 + //appendRight + matrix = new BigIntegerMatrix(grid10); + secondMatrix = new BigIntegerMatrix(grid10); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)} + }); + assertEquals("BigIntegerMatrix 10x10 failed appendRight.", correctMatrix, matrix.appendRight(secondMatrix)); + //appendBottom + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + }); + assertEquals("BigIntegerMatrix 10x10 failed appendBottom.", correctMatrix, matrix.appendBottom(secondMatrix)); + } + + @Test + public void testAddition(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix transformMatrix = new BigIntegerMatrix(transformGrid1_1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.TWO}}); + assertEquals("BigIntegerMatrix 1x1 failed add BigIntegerMatrix.", correctMatrix, matrix.add(transformMatrix)); + assertEquals("BigIntegerMatrix 1x1 failed add scalar.", correctMatrix, matrix.add(BigInteger.ONE)); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + transformMatrix = new BigIntegerMatrix(transformGrid2_1); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.TWO}, + {BigInteger.TWO, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 2x2 failed add BigIntegerMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 2x2 failed add scalar.", correctMatrix, matrix.add(BigInteger.ONE)); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + transformMatrix = new BigIntegerMatrix(transformGrid3_1); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3)}, + {BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3)}, + {BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 3x3 failed add BigIntegerMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 3x3 failed add scalar.", correctMatrix, matrix.add(BigInteger.ONE)); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + transformMatrix = new BigIntegerMatrix(transformGrid4_1); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4)}, + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4)}, + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4)}, + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed add BigIntegerMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)} + }); + assertEquals("BigIntegerMatrix 4x4 failed add scalar.", correctMatrix, matrix.add(BigInteger.ONE)); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + transformMatrix = new BigIntegerMatrix(transformGrid10_1); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)} + }); + assertEquals("BigIntegerMatrix 5x5 failed add BigIntegerMatrix.", correctMatrix, matrix.add(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.valueOf(11)} + }); + assertEquals("BigIntegerMatrix 10x10 failed add BigIntegerMatrix.", correctMatrix, matrix.add(BigInteger.ONE)); + } + + @Test + public void testSubtraction(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix transformMatrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO} + }); + assertEquals("BigIntegerMatrix 1x1 failed subtract BigIntegerMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + assertEquals("BigIntegerMatrix 1x1 failed subtract scalar.", correctMatrix, matrix.subtract(BigInteger.ONE)); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + transformMatrix = new BigIntegerMatrix(grid2); + correctMatrix = new BigIntegerMatrix(2, 2, BigInteger.ZERO); + assertEquals("BigIntegerMatrix 2x2 failed subtract BigIntegerMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.ONE}, + {BigInteger.ZERO, BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 2x2 failed subtract scalar.", correctMatrix, matrix.subtract(BigInteger.ONE)); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + transformMatrix = new BigIntegerMatrix(grid3); + correctMatrix = new BigIntegerMatrix(3, 3, BigInteger.ZERO); + assertEquals("BigIntegerMatrix 3x3 failed subtract BigIntegerMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 3x3 failed subtract scalar.", correctMatrix, matrix.subtract(BigInteger.ONE)); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + transformMatrix = new BigIntegerMatrix(grid4); + correctMatrix = new BigIntegerMatrix(4, 4, BigInteger.ZERO); + assertEquals("BigIntegerMatrix 4x4 failed subtract BigIntegerMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 4x4 failed subtract scalar.", correctMatrix, matrix.subtract(BigInteger.ONE)); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + transformMatrix = new BigIntegerMatrix(grid10); + correctMatrix = new BigIntegerMatrix(10, 10, BigInteger.ZERO); + assertEquals("BigIntegerMatrix 10x10 failed subtract BigIntegerMatrix.", correctMatrix, matrix.subtract(transformMatrix)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)}, + {BigInteger.ZERO, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9)} + }); + assertEquals("BigIntegerMatrix 10x10 failed subtract scalar.", correctMatrix, matrix.subtract(BigInteger.ONE)); + } + + @Test + public void testMultiplication(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix transformMatrix = new BigIntegerMatrix(transformGrid1_2); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(transformGrid1_2); + assertEquals("BigIntegerMatrix 1x1 failed multiplication BigIntegerMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + assertEquals("BigIntegerMatrix 1x1 failed multiplication scalar.", correctMatrix, matrix.multiply(BigInteger.TWO)); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + transformMatrix = new BigIntegerMatrix(transformGrid2_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(6), BigInteger.valueOf(9)}, + {BigInteger.valueOf(6), BigInteger.valueOf(9)} + }); + assertEquals("BigIntegerMatrix 2x2 failed multiplication BigIntegerMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + BigIntegerMatrix vector = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO}, + {BigInteger.valueOf(3)} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(8)}, + {BigInteger.valueOf(8)} + }); + assertEquals("BigIntegerMatrix 2x2 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 2x2 failed multiplication scalar.", correctMatrix, matrix.multiply(BigInteger.TWO)); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + transformMatrix = new BigIntegerMatrix(transformGrid3_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(12), BigInteger.valueOf(18), BigInteger.valueOf(24)}, + {BigInteger.valueOf(12), BigInteger.valueOf(18), BigInteger.valueOf(24)}, + {BigInteger.valueOf(12), BigInteger.valueOf(18), BigInteger.valueOf(24)} + }); + assertEquals("BigIntegerMatrix 3x3 failed multiplication BigIntegerMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + vector = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO}, + {BigInteger.valueOf(3)}, + {BigInteger.valueOf(4)} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(20)}, + {BigInteger.valueOf(20)}, + {BigInteger.valueOf(20)} + }); + assertEquals("BigIntegerMatrix 3x3 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6)} + }); + assertEquals("BigIntegerMatrix 3x3 failed multiplication scalar.", correctMatrix, matrix.multiply(BigInteger.TWO)); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + transformMatrix = new BigIntegerMatrix(transformGrid4_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(40), BigInteger.valueOf(50)}, + {BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(40), BigInteger.valueOf(50)}, + {BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(40), BigInteger.valueOf(50)}, + {BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(40), BigInteger.valueOf(50)}, + }); + assertEquals("BigIntegerMatrix 4x4 failed multiplication BigIntegerMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + vector = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO}, + {BigInteger.valueOf(3)}, + {BigInteger.valueOf(4)}, + {BigInteger.valueOf(5)} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(40)}, + {BigInteger.valueOf(40)}, + {BigInteger.valueOf(40)}, + {BigInteger.valueOf(40)} + }); + assertEquals("BigIntegerMatrix 4x4 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8)} + }); + assertEquals("BigIntegerMatrix 4x4 failed multiplication scalar.", correctMatrix, matrix.multiply(BigInteger.TWO)); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + transformMatrix = new BigIntegerMatrix(transformGrid10_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)}, + {BigInteger.valueOf(110), BigInteger.valueOf(165), BigInteger.valueOf(220), BigInteger.valueOf(275), BigInteger.valueOf(330), BigInteger.valueOf(385), BigInteger.valueOf(440), BigInteger.valueOf(495), BigInteger.valueOf(550), BigInteger.valueOf(605)} + }); + assertEquals("BigIntegerMatrix 10x10 failed multiplication BigIntegerMatrix.", correctMatrix, matrix.multiply(transformMatrix)); + vector = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO}, + {BigInteger.valueOf(3)}, + {BigInteger.valueOf(4)}, + {BigInteger.valueOf(5)}, + {BigInteger.valueOf(6)}, + {BigInteger.valueOf(7)}, + {BigInteger.valueOf(8)}, + {BigInteger.valueOf(9)}, + {BigInteger.valueOf(10)}, + {BigInteger.valueOf(11)} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)}, + {BigInteger.valueOf(440)} + }); + assertEquals("BigIntegerMatrix 10x10 failed multiplication vector.", correctMatrix, matrix.multiply(vector)); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.valueOf(6), BigInteger.valueOf(8), BigInteger.valueOf(10), BigInteger.valueOf(12), BigInteger.valueOf(14), BigInteger.valueOf(16), BigInteger.valueOf(18), BigInteger.valueOf(20)} + }); + assertEquals("BigIntegerMatrix 10x10 failed multiplication scalar.", correctMatrix, matrix.multiply(BigInteger.TWO)); + } + + @Test + public void testDotProduct(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix transformMatrix = new BigIntegerMatrix(transformGrid1_2); + assertEquals("BigIntegerMatrix 1x1 failed dot product BigIntegerMatrix.", BigInteger.TWO, matrix.dotProduct(transformMatrix)); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + transformMatrix = new BigIntegerMatrix(transformGrid2_2); + assertEquals("BigIntegerMatrix 2x2 failed dot product BigIntegerMatrix.", BigInteger.valueOf(30), matrix.dotProduct(transformMatrix)); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + transformMatrix = new BigIntegerMatrix(transformGrid3_2); + assertEquals("BigIntegerMatrix 3x3 failed dot product BigIntegerMatrix.", BigInteger.valueOf(162), matrix.dotProduct(transformMatrix)); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + transformMatrix = new BigIntegerMatrix(transformGrid4_2); + assertEquals("BigIntegerMatrix 4x4 failed dot product BigIntegerMatrix.", BigInteger.valueOf(560), matrix.dotProduct(transformMatrix)); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + transformMatrix = new BigIntegerMatrix(transformGrid10_2); + assertEquals("BigIntegerMatrix 10x10 failed dot product BigIntegerMatrix.", BigInteger.valueOf(35750), matrix.dotProduct(transformMatrix)); + } + + @Test + public void testHadamardProduct(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix transformMatrix = new BigIntegerMatrix(transformGrid1_2); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.TWO}}); + assertEquals("BigIntegerMatrix 1x1 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + transformMatrix = new BigIntegerMatrix(transformGrid2_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(6)}, + {BigInteger.TWO, BigInteger.valueOf(6)} + }); + assertEquals("BigIntegerMatrix 2x2 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + transformMatrix = new BigIntegerMatrix(transformGrid3_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12)} + }); + assertEquals("BigIntegerMatrix 3x3 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + transformMatrix = new BigIntegerMatrix(transformGrid4_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20)} + }); + assertEquals("BigIntegerMatrix 4x4 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + transformMatrix = new BigIntegerMatrix(transformGrid10_2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)}, + {BigInteger.TWO, BigInteger.valueOf(6), BigInteger.valueOf(12), BigInteger.valueOf(20), BigInteger.valueOf(30), BigInteger.valueOf(42), BigInteger.valueOf(56), BigInteger.valueOf(72), BigInteger.valueOf(90), BigInteger.valueOf(110)} + }); + assertEquals("BigIntegerMatrix 10x10 failed hadamard product.", correctMatrix, matrix.hadamardProduct(transformMatrix)); + } + + @Test + public void testTranspose(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed transpose.", correctMatrix, matrix.transpose()); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.ONE}, + {BigInteger.TWO, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 2x2 failed transpose.", correctMatrix, matrix.transpose()); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE}, + {BigInteger.TWO, BigInteger.TWO, BigInteger.TWO}, + {BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 3x3 failed transpose.", correctMatrix, matrix.transpose()); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE}, + {BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO}, + {BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3)}, + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed transpose.", correctMatrix, matrix.transpose()); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE}, + {BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO, BigInteger.TWO}, + {BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(3)}, + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(4)}, + {BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5), BigInteger.valueOf(5)}, + {BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6), BigInteger.valueOf(6)}, + {BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7), BigInteger.valueOf(7)}, + {BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8), BigInteger.valueOf(8)}, + {BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9), BigInteger.valueOf(9)}, + {BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10), BigInteger.valueOf(10)}, + }); + assertEquals("BigIntegerMatrix 10x10 failed transpose.", correctMatrix, matrix.transpose()); + } + + @Test + public void testDeterminant(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + assertEquals("BigIntegerMatrix 1x1 failed determinant.", BigInteger.ONE, matrix.determinant()); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + assertEquals("BigIntegerMatrix 2x2 failed determinant1.", BigInteger.ZERO, matrix.determinant()); + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.valueOf(4)}, + {BigInteger.valueOf(4), BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 2x2 failed determinant2.", BigInteger.valueOf(-15), matrix.determinant()); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + assertEquals("BigIntegerMatrix 3x3 failed determinant1.", BigInteger.ZERO, matrix.determinant()); + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.valueOf(4), BigInteger.TWO}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.ONE}, + {BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO} + }); + assertEquals("BigIntegerMatrix 3x3 failed determinant2.", BigInteger.valueOf(-21), matrix.determinant()); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + assertEquals("BigIntegerMatrix 4x4 failed determiant1.", BigInteger.ZERO, matrix.determinant()); + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE}, + {BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO}, + {BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + assertEquals("BigIntegerMatrix 4x4 failed determinant2.", BigInteger.valueOf(160), matrix.determinant()); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + assertEquals("BigIntegerMatrix 10x10 failed determinant1.", BigInteger.ZERO, matrix.determinant()); + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE}, + {BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO}, + {BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)}, + {BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5)}, + {BigInteger.valueOf(7), BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6)}, + {BigInteger.valueOf(8), BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7)}, + {BigInteger.valueOf(9), BigInteger.valueOf(10), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(6), BigInteger.valueOf(7), BigInteger.valueOf(8)}, + {BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 10x10 failed determinant2.", BigInteger.valueOf(-10000000), matrix.determinant()); + } + + @Test + public void testCofactor(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(grid1); + assertEquals("BigIntegerMatrix 1x1 failed cofactor.", correctMatrix, matrix.cofactor()); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.ONE.negate()}, + {BigInteger.TWO.negate(), BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 2x2 failed cofactor.", correctMatrix, matrix.cofactor()); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + correctMatrix = new BigIntegerMatrix(3, 3, BigInteger.ZERO); + assertEquals("BigIntegerMatrix 3x3 failed cofactor1.", correctMatrix, matrix.cofactor()); + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.valueOf(4), BigInteger.TWO}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.ONE}, + {BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(7), BigInteger.ZERO, BigInteger.valueOf(-14)}, + {BigInteger.valueOf(-6), BigInteger.valueOf(-6), BigInteger.valueOf(15)}, + {BigInteger.valueOf(-4), BigInteger.valueOf(3), BigInteger.valueOf(-4)} + }); + assertEquals("BigIntegerMatrix 3x3 failed cofactor2.", correctMatrix, matrix.cofactor()); + + //4x4 + matrix = new BigIntegerMatrix(grid4); + correctMatrix = new BigIntegerMatrix(4, 4, BigInteger.ZERO); + assertEquals("BigIntegerMatrix 4x4 failed cofactor1.", correctMatrix, matrix.cofactor()); + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE}, + {BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO}, + {BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(-36), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(44)}, + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(44), BigInteger.valueOf(-36)}, + {BigInteger.valueOf(4), BigInteger.valueOf(44), BigInteger.valueOf(-36), BigInteger.valueOf(4)}, + {BigInteger.valueOf(44), BigInteger.valueOf(-36), BigInteger.valueOf(4), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed cofactor2.", correctMatrix, matrix.cofactor()); + + //10x10 + //?Skipping 10x10 test because test took > 5s by itself + /* + matrix = new BigIntegerMatrix(grid10); + correctMatrix = new BigIntegerMatrix(10, BigInteger.valueOf(10), 0); + assertEquals("BigIntegerMatrix 10x10 failed cofactor1.", correctMatrix, matrix.cofactor()); + */ + } + + @Test + public void testPower(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(new BigInteger[][]{{BigInteger.ONE}}); + assertEquals("BigIntegerMatrix 1x1 failed power.", correctMatrix, matrix.pow(3)); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(9), BigInteger.valueOf(18)}, + {BigInteger.valueOf(9), BigInteger.valueOf(18)} + }); + assertEquals("BigIntegerMatrix 2x2 failed power.", correctMatrix, matrix.pow(3)); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(36), BigInteger.valueOf(72), BigInteger.valueOf(108)}, + {BigInteger.valueOf(36), BigInteger.valueOf(72), BigInteger.valueOf(108)}, + {BigInteger.valueOf(36), BigInteger.valueOf(72), BigInteger.valueOf(108)} + }); + assertEquals("BigIntegerMatrix 3x3 failed power.", correctMatrix, matrix.pow(3)); + + //4x4 + //0 + matrix = new BigIntegerMatrix(grid4); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE}, + {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE}, + {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE}, + {BigInteger.ONE, BigInteger.ONE, BigInteger.ONE, BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 4x4 failed power 0.", correctMatrix, matrix.pow(0)); + //1 + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed power 1.", correctMatrix, matrix.pow(1)); + //3 + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(100), BigInteger.valueOf(200), BigInteger.valueOf(300), BigInteger.valueOf(400)}, + {BigInteger.valueOf(100), BigInteger.valueOf(200), BigInteger.valueOf(300), BigInteger.valueOf(400)}, + {BigInteger.valueOf(100), BigInteger.valueOf(200), BigInteger.valueOf(300), BigInteger.valueOf(400)}, + {BigInteger.valueOf(100), BigInteger.valueOf(200), BigInteger.valueOf(300), BigInteger.valueOf(400)} + }); + assertEquals("BigIntegerMatrix 4x4 failed power 3.", correctMatrix, matrix.pow(3)); + + //10x10 + matrix = new BigIntegerMatrix(grid10); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)}, + {BigInteger.valueOf(3025), BigInteger.valueOf(6050), BigInteger.valueOf(9075), BigInteger.valueOf(12100), BigInteger.valueOf(15125), BigInteger.valueOf(18150), BigInteger.valueOf(21175), BigInteger.valueOf(24200), BigInteger.valueOf(27225), BigInteger.valueOf(30250)} + }); + assertEquals("BigIntegerMatrix 10x10 failed power.", correctMatrix, matrix.pow(3)); + } + + @Test + public void testAdjoint(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(grid1); + assertEquals("BigIntegerMatrix 1x1 failed adjoint.", correctMatrix, matrix.adjoint()); + + //2x2 + matrix = new BigIntegerMatrix(grid2); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.TWO, BigInteger.TWO.negate()}, + {BigInteger.ONE.negate(), BigInteger.ONE} + }); + assertEquals("BigIntegerMatrix 2x2 failed adjoint.", correctMatrix, matrix.adjoint()); + + //3x3 + matrix = new BigIntegerMatrix(grid3); + correctMatrix = new BigIntegerMatrix(3, 3, BigInteger.ZERO); + assertEquals("BigIntegerMatrix 3x3 failed adjoint.", correctMatrix, matrix.adjoint()); + + //4x4 + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE}, + {BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO}, + {BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.valueOf(-36), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(44)}, + {BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(44), BigInteger.valueOf(-36)}, + {BigInteger.valueOf(4), BigInteger.valueOf(44), BigInteger.valueOf(-36), BigInteger.valueOf(4)}, + {BigInteger.valueOf(44), BigInteger.valueOf(-36), BigInteger.valueOf(4), BigInteger.valueOf(4)} + }); + assertEquals("BigIntegerMatrix 4x4 failed adjoint.", correctMatrix, matrix.adjoint()); + + //10x10 + //?Skipping 10x10 test because test took > 5s by itself + /* + matrix = new BigIntegerMatrix(grid10); + correctMatrix = new BigIntegerMatrix(10, BigInteger.valueOf(10), 0); + assertEquals("BigIntegerMatrix 10x10 failed adjoint.", correctMatrix, matrix.adjoint()); + */ + } + + @Test + public void testInverse(){ + //1x1 + BigIntegerMatrix matrix = new BigIntegerMatrix(grid1); + BigIntegerMatrix correctMatrix = new BigIntegerMatrix(grid1); + assertEquals("BigIntegerMatrix 1x1 failed inverse.", correctMatrix, matrix.inverse()); + + //2x2 + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.valueOf(4)}, + {BigInteger.valueOf(4), BigInteger.ONE} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO.negate(), BigInteger.ZERO}, + {BigInteger.ZERO, BigInteger.ZERO.negate()} + }); + assertEquals("BigIntegerMatrix 2x2 failed inverse.", correctMatrix, matrix.inverse()); + + //3x3 + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.valueOf(4), BigInteger.TWO}, + {BigInteger.TWO, BigInteger.valueOf(4), BigInteger.ONE}, + {BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO.negate(), BigInteger.ZERO, BigInteger.ZERO}, + {BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO.negate()}, + {BigInteger.ZERO, BigInteger.ZERO.negate(), BigInteger.ZERO} + }); + assertEquals("BigIntegerMatrix 3x3 failed inverse.", correctMatrix, matrix.inverse()); + + //4x4 + matrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4)}, + {BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE}, + {BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO}, + {BigInteger.valueOf(4), BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3)} + }); + correctMatrix = new BigIntegerMatrix(new BigInteger[][]{ + {BigInteger.ZERO.negate(), BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO}, + {BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO.negate()}, + {BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO.negate(), BigInteger.ZERO}, + {BigInteger.ZERO, BigInteger.ZERO.negate(), BigInteger.ZERO, BigInteger.ZERO} + }); + assertEquals("BigIntegerMatrix 4x4 failed inverse.", correctMatrix, matrix.inverse()); + + //10x10 + //?Skipped 10x10 because it would take a long time to compute + } +} 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 + } +}