2614 lines
68 KiB
Java
2614 lines
68 KiB
Java
package com.mattrixwv.matrix;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import com.mattrixwv.matrix.exceptions.InvalidCoordinatesException;
|
|
import com.mattrixwv.matrix.exceptions.InvalidGeometryException;
|
|
import com.mattrixwv.matrix.exceptions.InvalidRowSizeException;
|
|
import com.mattrixwv.matrix.exceptions.InvalidScalarException;
|
|
import com.mattrixwv.matrix.exceptions.NullMatrixException;
|
|
|
|
|
|
public class TestModMatrix{
|
|
private static final int[][] negativeGrid2 = new int[][]{
|
|
{-1, -2},
|
|
{-3, -4}
|
|
};
|
|
private static final int[][] negativeGrid2Mod26 = new int[][]{
|
|
{25, 24},
|
|
{23, 22}
|
|
};
|
|
private static final int[][] negativeGrid10 = new int[][]{
|
|
{ -1, -2, -3, -4, -5, -6, -7, -8, -9, -10},
|
|
{-11, -12, -13, -14, -15, -16, -17, -18, -19, -20},
|
|
{-21, -22, -23, -24, -25, -26, -27, -28, -29, -30},
|
|
{-31, -32, -33, -34, -35, -36, -37, -38, -39, -40},
|
|
{-41, -42, -43, -44, -45, -46, -47, -48, -49, -50},
|
|
{-51, -52, -53, -54, -55, -56, -57, -58, -59, -60},
|
|
{-61, -62, -63, -64, -65, -66, -67, -68, -69, -70},
|
|
{-71, -72, -73, -74, -75, -76, -77, -78, -79, -80},
|
|
{-81, -82, -83, -84, -85, -86, -87, -88, -89, -90},
|
|
{-91, -92, -93, -94, -95, -96, -97, -98, -99, -100}
|
|
};
|
|
private static final int[][] negativeGrid10Mod26 = new int[][]{
|
|
{25, 24, 23, 22, 21, 20, 19, 18, 17, 16},
|
|
{15, 14, 13, 12, 11, 10, 9, 8, 7, 6},
|
|
{ 5, 4, 3, 2, 1, 0, 25, 24, 23, 22},
|
|
{21, 20, 19, 18, 17, 16, 15, 14, 13, 12},
|
|
{11, 10, 9, 8, 7, 6, 5, 4, 3, 2},
|
|
{ 1, 0, 25, 24, 23, 22, 21, 20, 19, 18},
|
|
{17, 16, 15, 14, 13, 12, 11, 10, 9, 8},
|
|
{ 7, 6, 5, 4, 3, 2, 1, 0, 25, 24},
|
|
{23, 22, 21, 20, 19, 18, 17, 16, 15, 14},
|
|
{13, 12, 11, 10, 9, 8, 7, 6, 5, 4}
|
|
};
|
|
private static final int[][] negativeGrid2x10 = new int[][]{
|
|
{ -1, -2, -3, -4, -5, -6, -7, -8, -9, -10},
|
|
{-11, -12, -13, -14, -15, -16, -17, -18, -19, -20}
|
|
};
|
|
private static final int[][] negativeGrid2x10Mod26 = new int[][]{
|
|
{25, 24, 23, 22, 21, 20, 19, 18, 17, 16},
|
|
{15, 14, 13, 12, 11, 10, 9, 8, 7, 6}
|
|
};
|
|
private static final int[][] negativeGrid10x2 = new int[][]{
|
|
{ -1, -2},
|
|
{ -3, -4},
|
|
{ -5, -6},
|
|
{ -7, -8},
|
|
{ -9, -10},
|
|
{-11, -12},
|
|
{-13, -14},
|
|
{-15, -16},
|
|
{-17, -18},
|
|
{-19, -20}
|
|
};
|
|
private static final int[][] negativeGrid10x2Mod26 = new int[][]{
|
|
{25, 24},
|
|
{23, 22},
|
|
{21, 20},
|
|
{19, 18},
|
|
{17, 16},
|
|
{15, 14},
|
|
{13, 12},
|
|
{11, 10},
|
|
{ 9, 8},
|
|
{ 7, 6}
|
|
};
|
|
private static final int MOD = 26;
|
|
|
|
|
|
//! Constructor
|
|
@Test
|
|
public void testConstructor_mod(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertEquals(0, matrix.getNumRows());
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_fill0Rows(){
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
new ModMatrix(0, 1, 0, MOD);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_fill0Cols(){
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
new ModMatrix(1, 0, 0, MOD);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_fillSize2(){
|
|
ModMatrix matrix = new ModMatrix(2, 2, -1, MOD);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(2, matrix.getNumCols());
|
|
assertEquals(25, matrix.get(0, 0));
|
|
assertEquals(25, matrix.get(0, 1));
|
|
assertEquals(25, matrix.get(1, 0));
|
|
assertEquals(25, matrix.get(1, 1));
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_fillSize10(){
|
|
ModMatrix matrix = new ModMatrix(10, 10, -1, MOD);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
assertEquals(10, matrix.getNumCols());
|
|
for(int[] row : matrix.copyGrid()){
|
|
for(int num : row){
|
|
assertEquals(25, num);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_arraySize0(){
|
|
int[][] grid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertEquals(0, matrix.getNumRows());
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_arraySize2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(2, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid2Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_arraySize10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
assertEquals(10, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid10Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_arraySize2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(10, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid2x10Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_arraySize10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
assertEquals(2, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid10x2Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_arrayUnevenRows(){
|
|
int[][] grid = new int[][]{
|
|
{-1, -2, -3},
|
|
{-4, -5},
|
|
{-6, -7, -8, -9},
|
|
{-10, -11, -12}
|
|
};
|
|
|
|
assertThrows(InvalidRowSizeException.class, () -> {
|
|
new ModMatrix(grid, MOD);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_matrixSize0(){
|
|
ModMatrix originalMatrix = new ModMatrix(MOD);
|
|
ModMatrix matrix = new ModMatrix(originalMatrix);
|
|
|
|
assertEquals(0, matrix.getNumRows());
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_matrixSize2(){
|
|
ModMatrix originalMatrix = new ModMatrix(2, 2, -1, MOD);
|
|
ModMatrix matrix = new ModMatrix(originalMatrix);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(2, matrix.getNumCols());
|
|
for(int[] row : matrix.copyGrid()){
|
|
for(int num : row){
|
|
assertEquals(25, num);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_matrixSize10(){
|
|
ModMatrix originalMatrix = new ModMatrix(10, 10, -1, MOD);
|
|
ModMatrix matrix = new ModMatrix(originalMatrix);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
assertEquals(10, matrix.getNumCols());
|
|
for(int[] row : matrix.copyGrid()){
|
|
for(int num : row){
|
|
assertEquals(25, num);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_matrixSize2x10(){
|
|
ModMatrix originalMatrix = new ModMatrix(2, 10, -1, MOD);
|
|
ModMatrix matrix = new ModMatrix(originalMatrix);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(10, matrix.getNumCols());
|
|
for(int[] row : matrix.copyGrid()){
|
|
for(int num : row){
|
|
assertEquals(25, num);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testConstructor_matrixSize10x2(){
|
|
ModMatrix originalMatrix = new ModMatrix(10, 2, -1, MOD);
|
|
ModMatrix matrix = new ModMatrix(originalMatrix);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
assertEquals(2, matrix.getNumCols());
|
|
for(int[] row : matrix.copyGrid()){
|
|
for(int num : row){
|
|
assertEquals(25, num);
|
|
}
|
|
}
|
|
}
|
|
|
|
//! setGrid()
|
|
@Test
|
|
public void testSetGrid_size0(){
|
|
int[][] grid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
matrix.setGrid(grid);
|
|
|
|
assertEquals(0, matrix.getNumRows());
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testSetGrid_size2x0(){
|
|
int[][] grid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
matrix.setGrid(grid);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testSetGrid_size2(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
matrix.setGrid(negativeGrid2);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(2, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid2Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetGrid_size10(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
matrix.setGrid(negativeGrid10);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
assertEquals(10, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid10Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetGrid_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
matrix.setGrid(negativeGrid2x10);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
assertEquals(10, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid2x10Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetGrid_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
matrix.setGrid(negativeGrid10x2);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
assertEquals(2, matrix.getNumCols());
|
|
assertArrayEquals(negativeGrid10x2Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCopyGrid_size0(){
|
|
int[][] grid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertArrayEquals(grid, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCopyGrid_size0x2(){
|
|
int[][] grid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertArrayEquals(grid, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCopyGrid_size2x0(){
|
|
int[][] grid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertArrayEquals(grid, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCopyGrid_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertArrayEquals(negativeGrid2Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCopyGrid_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertArrayEquals(negativeGrid10Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCopyGrid_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertArrayEquals(negativeGrid10x2Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCopyGrid_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertArrayEquals(negativeGrid2x10Mod26, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetGrid(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.setGrid(negativeGrid2);
|
|
|
|
assertArrayEquals(negativeGrid2Mod26, matrix.grid);
|
|
}
|
|
|
|
//! setMod()
|
|
@Test
|
|
public void testSetMod_negative(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertThrows(InvalidScalarException.class, () -> {
|
|
matrix.setMod(-1);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetMod_0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertThrows(InvalidScalarException.class, () -> {
|
|
matrix.setMod(0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetMod(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
matrix.setMod(2);
|
|
|
|
assertEquals(2, matrix.mod);
|
|
}
|
|
|
|
//! modValue()
|
|
@Test
|
|
public void testModValue_negative(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
int value = matrix.modValue(-1);
|
|
|
|
assertEquals(25, value);
|
|
}
|
|
|
|
@Test
|
|
public void testModValue_negativeLarge(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
int value = matrix.modValue(-28);
|
|
|
|
assertEquals(24, value);
|
|
}
|
|
|
|
@Test
|
|
public void testModValue_small(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
int value = matrix.modValue(1);
|
|
|
|
assertEquals(1, value);
|
|
}
|
|
|
|
@Test
|
|
public void testModValue_large(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
int value = matrix.modValue(28);
|
|
|
|
assertEquals(2, value);
|
|
}
|
|
|
|
//! modValues()
|
|
@Test
|
|
public void testModValues_null(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.modValues(null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testModValues(){
|
|
int[] values = new int[]{1, 2, 27, 28, -1, -2};
|
|
int[] expectedValues = new int[]{1, 2, 1, 2, 25, 24};
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
int[] returnedValues = matrix.modValues(values);
|
|
|
|
assertArrayEquals(expectedValues, returnedValues);
|
|
}
|
|
|
|
//! modGrid()
|
|
@Test
|
|
public void testModGrid_size0(){
|
|
int[][] expectedGrid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
matrix.modGrid();
|
|
|
|
assertArrayEquals(expectedGrid, matrix.grid);
|
|
}
|
|
|
|
@Test
|
|
public void testModGrid_size0x2(){
|
|
int[][] expectedGrid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(new int[0][2], MOD);
|
|
matrix.modGrid();
|
|
|
|
assertArrayEquals(expectedGrid, matrix.grid);
|
|
}
|
|
|
|
@Test
|
|
public void testModGrid_size2x0(){
|
|
int[][] expectedGrid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(new int[2][0], MOD);
|
|
matrix.modGrid();
|
|
|
|
assertArrayEquals(expectedGrid, matrix.grid);
|
|
}
|
|
|
|
@Test
|
|
public void testModGrid_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.grid = negativeGrid2;
|
|
matrix.modGrid();
|
|
|
|
assertArrayEquals(negativeGrid2Mod26, matrix.grid);
|
|
}
|
|
|
|
@Test
|
|
public void testModGrid_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
matrix.grid = negativeGrid10;
|
|
matrix.modGrid();
|
|
|
|
assertArrayEquals(negativeGrid10Mod26, matrix.grid);
|
|
}
|
|
|
|
@Test
|
|
public void testModGrid_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
matrix.grid = negativeGrid2x10;
|
|
matrix.modGrid();
|
|
|
|
assertArrayEquals(negativeGrid2x10Mod26, matrix.grid);
|
|
}
|
|
|
|
@Test
|
|
public void testModGrid_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
matrix.grid = negativeGrid10x2;
|
|
matrix.modGrid();
|
|
|
|
assertArrayEquals(negativeGrid10x2Mod26, matrix.grid);
|
|
}
|
|
|
|
//! getMod()
|
|
@Test
|
|
public void testGetMod(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertEquals(MOD, matrix.getMod());
|
|
}
|
|
|
|
//! isSquare()
|
|
@Test
|
|
public void testIsSquare_size0(){
|
|
int[][] grid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertFalse(matrix.isSquare());
|
|
}
|
|
|
|
@Test
|
|
public void testIsSquare_size0x2(){
|
|
int[][] grid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertFalse(matrix.isSquare());
|
|
}
|
|
|
|
@Test
|
|
public void testIsSquare_size2x0(){
|
|
int[][] grid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertFalse(matrix.isSquare());
|
|
}
|
|
|
|
@Test
|
|
public void testIsSquare_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertTrue(matrix.isSquare());
|
|
}
|
|
|
|
@Test
|
|
public void testIsSquare_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertTrue(matrix.isSquare());
|
|
}
|
|
|
|
@Test
|
|
public void testIsSquare_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertFalse(matrix.isSquare());
|
|
}
|
|
|
|
@Test
|
|
public void testIsSquare_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertFalse(matrix.isSquare());
|
|
}
|
|
|
|
//! laplaceExpansionHelper()
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size0(){
|
|
int[][] grid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.laplaceExpansionHelper(0, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size0x2(){
|
|
int[][] grid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.laplaceExpansionHelper(0, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size2x0(){
|
|
int[][] grid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.laplaceExpansionHelper(0, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
IntegerMatrix result = matrix.laplaceExpansionHelper(0, 0);
|
|
|
|
assertArrayEquals(new int[][]{{22}}, result.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size2_negativeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.laplaceExpansionHelper(-1, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size2_largeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.laplaceExpansionHelper(2, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size2_negativeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.laplaceExpansionHelper(0, -1);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size2_largeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.laplaceExpansionHelper(0, 2);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size10_loc0x0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
IntegerMatrix result = matrix.laplaceExpansionHelper(0, 0);
|
|
|
|
int[][] expectedGrid = new int[][]{
|
|
{14, 13, 12, 11, 10, 9, 8, 7, 6},
|
|
{ 4, 3, 2, 1, 0, 25, 24, 23, 22},
|
|
{20, 19, 18, 17, 16, 15, 14, 13, 12},
|
|
{10, 9, 8, 7, 6, 5, 4, 3, 2},
|
|
{ 0, 25, 24, 23, 22, 21, 20, 19, 18},
|
|
{16, 15, 14, 13, 12, 11, 10, 9, 8},
|
|
{ 6, 5, 4, 3, 2, 1, 0, 25, 24},
|
|
{22, 21, 20, 19, 18, 17, 16, 15, 14},
|
|
{12, 11, 10, 9, 8, 7, 6, 5, 4}
|
|
};
|
|
assertArrayEquals(expectedGrid, result.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size10_loc4x4(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
IntegerMatrix result = matrix.laplaceExpansionHelper(4, 4);
|
|
|
|
int[][] expectedGrid = new int[][]{
|
|
{25, 24, 23, 22, 20, 19, 18, 17, 16},
|
|
{15, 14, 13, 12, 10, 9, 8, 7, 6},
|
|
{ 5, 4, 3, 2, 0, 25, 24, 23, 22},
|
|
{21, 20, 19, 18, 16, 15, 14, 13, 12},
|
|
{ 1, 0, 25, 24, 22, 21, 20, 19, 18},
|
|
{17, 16, 15, 14, 12, 11, 10, 9, 8},
|
|
{ 7, 6, 5, 4, 2, 1, 0, 25, 24},
|
|
{23, 22, 21, 20, 18, 17, 16, 15, 14},
|
|
{13, 12, 11, 10, 8, 7, 6, 5, 4}
|
|
};
|
|
assertArrayEquals(expectedGrid, result.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.laplaceExpansionHelper(0, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testLaplaceExpansionHelper_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.laplaceExpansionHelper(0, 0);
|
|
});
|
|
}
|
|
|
|
//! get()
|
|
@Test
|
|
public void testGet_largeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.get(2, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGet_negativeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.get(-1, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGet_largeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.get(0, 2);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGet_negativeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.get(0, -1);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGet(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertEquals(25, matrix.get(0, 0));
|
|
assertEquals(24, matrix.get(0, 1));
|
|
assertEquals(23, matrix.get(1, 0));
|
|
assertEquals(22, matrix.get(1, 1));
|
|
}
|
|
|
|
//! getRow()
|
|
@Test
|
|
public void testGetRow_largeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.getRow(2);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGetRow_negativeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.getRow(-1);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGetRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertArrayEquals(new int[][]{{25, 24}}, matrix.getRow(0).copyGrid());
|
|
assertArrayEquals(new int[][]{{23, 22}}, matrix.getRow(1).copyGrid());
|
|
}
|
|
|
|
//! getColumn()
|
|
@Test
|
|
public void testGetCol_0Rows(){
|
|
int[][] grid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.getCol(0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGetCol_largeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.getCol(2);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGetCol_negativeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.getCol(-1);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGetCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertArrayEquals(new int[][]{{25}, {23}}, matrix.getCol(0).copyGrid());
|
|
assertArrayEquals(new int[][]{{24}, {22}}, matrix.getCol(1).copyGrid());
|
|
}
|
|
|
|
//! getNumRows()
|
|
@Test
|
|
public void testGetNumRows_size0(){
|
|
int[][] grid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertEquals(0, matrix.getNumRows());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumRows_size0x2(){
|
|
int[][] grid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertEquals(0, matrix.getNumRows());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumRows_size2x0(){
|
|
int[][] grid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumRows_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumRows_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumRows_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertEquals(2, matrix.getNumRows());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumRows_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertEquals(10, matrix.getNumRows());
|
|
}
|
|
|
|
//! getNumCols()
|
|
@Test
|
|
public void testGetNumCols_size0(){
|
|
int[][] grid = new int[0][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumCols_size0x2(){
|
|
int[][] grid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumCols_size2x0(){
|
|
int[][] grid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertEquals(0, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumCols_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertEquals(2, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumCols_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertEquals(10, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumCols_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertEquals(10, matrix.getNumCols());
|
|
}
|
|
|
|
@Test
|
|
public void testGetNumCols_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertEquals(2, matrix.getNumCols());
|
|
}
|
|
|
|
//! set()
|
|
@Test
|
|
public void testSet_negativeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.set(-1, 0, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSet_largeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.set(2, 0, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSet_negativeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.set(0, -1, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSet_largeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.set(0, 2, 0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSet(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
matrix.set(0, 0, -5);
|
|
matrix.set(0, 1, -6);
|
|
matrix.set(1, 0, -7);
|
|
matrix.set(1, 1, -8);
|
|
assertEquals(21, matrix.get(0, 0));
|
|
assertEquals(20, matrix.get(0, 1));
|
|
assertEquals(19, matrix.get(1, 0));
|
|
assertEquals(18, matrix.get(1, 1));
|
|
}
|
|
|
|
//! setRow()
|
|
@Test
|
|
public void testSetRow_array_negativeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setRow(-1, new int[]{0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_array_largeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setRow(2, new int[]{0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_array_nullArray(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.setRow(0, (int[])null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_array_arrayLength0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setRow(0, new int[0]);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_array_invalidArrayLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setRow(0, new int[]{0, 0, 0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_array(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
matrix.setRow(0, new int[]{-5, -6});
|
|
matrix.setRow(1, new int[]{-7, -8});
|
|
assertArrayEquals(new int[][]{{21, 20}, {19, 18}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_matrix_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.setRow(0, (ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_matrix_multipleRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setRow(0, new ModMatrix(new int[][]{{0, 0}, {0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_matrix_negativeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setRow(-1, new ModMatrix(new int[][]{{0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_matrix_largeRow(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setRow(2, new ModMatrix(new int[][]{{0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_matrix_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setRow(0, new ModMatrix(new int[][]{{}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_matrix_invalidLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setRow(0, new ModMatrix(new int[][]{{0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_matrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
matrix.setRow(0, new ModMatrix(new int[][]{{-5, -6}}, MOD));
|
|
matrix.setRow(1, new ModMatrix(new int[][]{{-7, -8}}, MOD));
|
|
assertArrayEquals(new int[][]{{21, 20}, {19, 18}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetRow_integerMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
matrix.setRow(0, new IntegerMatrix(new int[][]{{-5, -6}}));
|
|
matrix.setRow(1, new IntegerMatrix(new int[][]{{-7, -8}}));
|
|
assertArrayEquals(new int[][]{{21, 20}, {19, 18}}, matrix.copyGrid());
|
|
}
|
|
|
|
//! setCol()
|
|
@Test
|
|
public void testSetCol_array_negativeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setCol(25, new int[]{0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_array_largeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setCol(2, new int[]{0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_array_nullArray(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setCol(0, (int[])null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_array_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setCol(0, new int[0]);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_array_invalidArrayLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setCol(0, new int[]{0, 0, 0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_array(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
matrix.setCol(0, new int[]{-5, -7});
|
|
matrix.setCol(1, new int[]{-6, -8});
|
|
assertArrayEquals(new int[][]{{21, 20}, {19, 18}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_matrix_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.setCol(0, (ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_matrix_multipleCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setCol(0, new ModMatrix(new int[][]{{0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_matrix_negativeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setCol(-1, new ModMatrix(new int[][]{{0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_matrix_largeCol(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidCoordinatesException.class, () -> {
|
|
matrix.setCol(2, new ModMatrix(new int[][]{{0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_matrix_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setCol(0, new ModMatrix(new int[][]{{}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_matrix_invalidLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.setCol(0, new ModMatrix(new int[][]{{0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_matrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
matrix.setCol(0, new ModMatrix(new int[][]{{-5}, {-7}}, MOD));
|
|
matrix.setCol(1, new ModMatrix(new int[][]{{-6}, {-8}}, MOD));
|
|
assertArrayEquals(new int[][]{{21, 20}, {19, 18}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSetCol_integerMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
matrix.setCol(0, new IntegerMatrix(new int[][]{{-5}, {-7}}));
|
|
matrix.setCol(1, new IntegerMatrix(new int[][]{{-6}, {-8}}));
|
|
assertArrayEquals(new int[][]{{21, 20}, {19, 18}}, matrix.copyGrid());
|
|
}
|
|
|
|
//! addRow()
|
|
@Test
|
|
public void testAddRow_array_nullArray(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.addRow((int[])null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_array_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addRow(new int[0]);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_array_invalidArrayLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addRow(new int[]{0, 0, 0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_array(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.addRow(new int[]{-5, -6});
|
|
|
|
assertArrayEquals(new int[][]{{25, 24}, {23, 22}, {21, 20}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_matrix_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.addRow((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_matrix_multipleRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addRow(new ModMatrix(new int[][]{{0, 0}, {0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_matrix_noRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addRow(new ModMatrix(new int[0][0], MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_matrix_invalidLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addRow(new ModMatrix(new int[][]{{0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_matrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.addRow(new ModMatrix(new int[][]{{-5, -6}}, MOD));
|
|
|
|
assertArrayEquals(new int[][]{{25, 24}, {23, 22}, {21, 20}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAddRow_integerMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.addRow(new IntegerMatrix(new int[][]{{-5, -6}}));
|
|
|
|
assertArrayEquals(new int[][]{{25, 24}, {23, 22}, {21, 20}}, matrix.copyGrid());
|
|
}
|
|
|
|
//! addCol()
|
|
@Test
|
|
public void testAddCol_array_nullArray(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.addCol((int[])null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_array_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addCol(new int[0]);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_array_invalidArrayLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addCol(new int[]{0, 0, 0});
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_array(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.addCol(new int[]{-5, -6});
|
|
|
|
assertArrayEquals(new int[][]{{25, 24, 21}, {23, 22, 20}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_matrix_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.addCol((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_matrix_multipleCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addCol(new ModMatrix(new int[][]{{0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_matrix_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addCol(new ModMatrix(new int[][]{{}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_matrix_invalidLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.addCol(new ModMatrix(new int[][]{{0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_matrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.addCol(new ModMatrix(new int[][]{{-5}, {-6}}, MOD));
|
|
|
|
assertArrayEquals(new int[][]{{25, 24, 21}, {23, 22, 20}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAddCol_integerMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix.addCol(new IntegerMatrix(new int[][]{{-5}, {-6}}));
|
|
|
|
assertArrayEquals(new int[][]{{25, 24, 21}, {23, 22, 20}}, matrix.copyGrid());
|
|
}
|
|
|
|
//! appendRight()
|
|
@Test
|
|
public void testAppendRight_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.appendRight((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAppendRight_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.appendRight(new ModMatrix(new int[0][0], MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAppendRight_invalidLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.appendRight(new ModMatrix(new int[][]{{0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAppendRight(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.appendRight(matrix);
|
|
|
|
assertArrayEquals(new int[][]{{25, 24, 25, 24}, {23, 22, 23, 22}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAppendRight_integerMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.appendRight(new IntegerMatrix(negativeGrid2));
|
|
|
|
assertArrayEquals(new int[][]{{25, 24, 25, 24}, {23, 22, 23, 22}}, matrix.copyGrid());
|
|
}
|
|
|
|
//! appendBottom()
|
|
@Test
|
|
public void testAppendBottom_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.appendBottom((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAppendBottom_length0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.appendBottom(new ModMatrix(new int[0][0], MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAppendBottom_invalidLength(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.appendBottom(new ModMatrix(new int[][]{{0}, {0}, {0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAppendBottom(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.appendBottom(matrix);
|
|
|
|
assertArrayEquals(new int[][]{{25, 24}, {23, 22}, {25, 24}, {23, 22}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAppendBottom_integerMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.appendBottom(new IntegerMatrix(negativeGrid2));
|
|
|
|
assertArrayEquals(new int[][]{{25, 24}, {23, 22}, {25, 24}, {23, 22}}, matrix.copyGrid());
|
|
}
|
|
|
|
//! add()
|
|
@Test
|
|
public void testAdd_matrix_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.add((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_matrix_fewRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.add(new ModMatrix(new int[][]{{0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_matrix_manyRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.add(new ModMatrix(new int[][]{{0}, {0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_matrix_fewCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.add(new ModMatrix(new int[][]{{0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_matrix_manyCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.add(new ModMatrix(new int[][]{{0, 0, 0}, {0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_matrix_size2(){
|
|
ModMatrix addMatrix = new ModMatrix(new int[][]{{22, 23}, {24, 25}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.add(addMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{21, 21}, {21, 21}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_matrix_size10(){
|
|
ModMatrix addMatrix = new ModMatrix(new int[][]{
|
|
{-100, -99, -98, -97, -96, -95, -94, -93, -92, -91},
|
|
{ -90, -89, -88, -87, -86, -85, -84, -83, -82, -81},
|
|
{ -80, -79, -78, -77, -76, -75, -74, -73, -72, -71},
|
|
{ -70, -69, -68, -67, -66, -65, -64, -63, -62, -61},
|
|
{ -60, -59, -58, -57, -56, -55, -54, -53, -52, -51},
|
|
{ -50, -49, -48, -47, -46, -45, -44, -43, -42, -41},
|
|
{ -40, -39, -38, -37, -36, -35, -34, -33, -32, -31},
|
|
{ -30, -29, -28, -27, -26, -25, -24, -23, -22, -21},
|
|
{ -20, -19, -18, -17, -16, -15, -14, -13, -12, -11},
|
|
{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}
|
|
}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
matrix = matrix.add(addMatrix);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
|
|
}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_scalar(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.add(1);
|
|
|
|
assertArrayEquals(new int[][]{{0, 25}, {24, 23}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_integerMatrix_size2(){
|
|
IntegerMatrix addMatrix = new IntegerMatrix(new int[][]{{22, 23}, {24, 25}});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.add(addMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{21, 21}, {21, 21}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAdd_integerMatrix_size10(){
|
|
IntegerMatrix addMatrix = new IntegerMatrix(new int[][]{
|
|
{-100, -99, -98, -97, -96, -95, -94, -93, -92, -91},
|
|
{ -90, -89, -88, -87, -86, -85, -84, -83, -82, -81},
|
|
{ -80, -79, -78, -77, -76, -75, -74, -73, -72, -71},
|
|
{ -70, -69, -68, -67, -66, -65, -64, -63, -62, -61},
|
|
{ -60, -59, -58, -57, -56, -55, -54, -53, -52, -51},
|
|
{ -50, -49, -48, -47, -46, -45, -44, -43, -42, -41},
|
|
{ -40, -39, -38, -37, -36, -35, -34, -33, -32, -31},
|
|
{ -30, -29, -28, -27, -26, -25, -24, -23, -22, -21},
|
|
{ -20, -19, -18, -17, -16, -15, -14, -13, -12, -11},
|
|
{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}
|
|
});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
matrix = matrix.add(addMatrix);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
|
|
{3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
|
|
}, matrix.copyGrid());
|
|
}
|
|
|
|
//! subtract()
|
|
@Test
|
|
public void testSubtract_matrix_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.subtract((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_matrix_fewRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.subtract(new ModMatrix(new int[][]{{0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_matrix_manyRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.subtract(new ModMatrix(new int[][]{{0, 0}, {0, 0}, {0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_matrix_fewCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.subtract(new ModMatrix(new int[][]{{0}, {0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_matrix_manyCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.subtract(new ModMatrix(new int[][]{{0, 0, 0}, {0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_matrix_size2(){
|
|
ModMatrix subMatrix = new ModMatrix(new int[][]{{-4, -3}, {-2, -1}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.subtract(subMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{3, 1}, {25, 23}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_matrix_size10(){
|
|
ModMatrix subMatrix = new ModMatrix(new int[][]{
|
|
{-100, -99, -98, -97, -96, -95, -94, -93, -92, -91},
|
|
{ -90, -89, -88, -87, -86, -85, -84, -83, -82, -81},
|
|
{ -80, -79, -78, -77, -76, -75, -74, -73, -72, -71},
|
|
{ -70, -69, -68, -67, -66, -65, -64, -63, -62, -61},
|
|
{ -60, -59, -58, -57, -56, -55, -54, -53, -52, -51},
|
|
{ -50, -49, -48, -47, -46, -45, -44, -43, -42, -41},
|
|
{ -40, -39, -38, -37, -36, -35, -34, -33, -32, -31},
|
|
{ -30, -29, -28, -27, -26, -25, -24, -23, -22, -21},
|
|
{ -20, -19, -18, -17, -16, -15, -14, -13, -12, -11},
|
|
{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}
|
|
}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
matrix = matrix.subtract(subMatrix);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{ 21, 19, 17, 15, 13, 11, 9, 7, 5, 3},
|
|
{ 1, 25, 23, 21, 19, 17, 15, 13, 11, 9},
|
|
{ 7, 5, 3, 1, 25, 23, 21, 19, 17, 15},
|
|
{ 13, 11, 9, 7, 5, 3, 1, 25, 23, 21},
|
|
{ 19, 17, 15, 13, 11, 9, 7, 5, 3, 1},
|
|
{ 25, 23, 21, 19, 17, 15, 13, 11, 9, 7},
|
|
{ 5, 3, 1, 25, 23, 21, 19, 17, 15, 13},
|
|
{ 11, 9, 7, 5, 3, 1, 25, 23, 21, 19},
|
|
{ 17, 15, 13, 11, 9, 7, 5, 3, 1, 25},
|
|
{ 23, 21, 19, 17, 15, 13, 11, 9, 7, 5}
|
|
}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_scalar(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.subtract(1);
|
|
|
|
assertArrayEquals(new int[][]{{24, 23}, {22, 21}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_integerMatrix_size2(){
|
|
IntegerMatrix subMatrix = new IntegerMatrix(new int[][]{{-4, -3}, {-2, -1}});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.subtract(subMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{3, 1}, {25, 23}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testSubtract_integerMatrix_size10(){
|
|
IntegerMatrix subMatrix = new IntegerMatrix(new int[][]{
|
|
{-100, -99, -98, -97, -96, -95, -94, -93, -92, -91},
|
|
{ -90, -89, -88, -87, -86, -85, -84, -83, -82, -81},
|
|
{ -80, -79, -78, -77, -76, -75, -74, -73, -72, -71},
|
|
{ -70, -69, -68, -67, -66, -65, -64, -63, -62, -61},
|
|
{ -60, -59, -58, -57, -56, -55, -54, -53, -52, -51},
|
|
{ -50, -49, -48, -47, -46, -45, -44, -43, -42, -41},
|
|
{ -40, -39, -38, -37, -36, -35, -34, -33, -32, -31},
|
|
{ -30, -29, -28, -27, -26, -25, -24, -23, -22, -21},
|
|
{ -20, -19, -18, -17, -16, -15, -14, -13, -12, -11},
|
|
{ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}
|
|
});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
matrix = matrix.subtract(subMatrix);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{ 21, 19, 17, 15, 13, 11, 9, 7, 5, 3},
|
|
{ 1, 25, 23, 21, 19, 17, 15, 13, 11, 9},
|
|
{ 7, 5, 3, 1, 25, 23, 21, 19, 17, 15},
|
|
{ 13, 11, 9, 7, 5, 3, 1, 25, 23, 21},
|
|
{ 19, 17, 15, 13, 11, 9, 7, 5, 3, 1},
|
|
{ 25, 23, 21, 19, 17, 15, 13, 11, 9, 7},
|
|
{ 5, 3, 1, 25, 23, 21, 19, 17, 15, 13},
|
|
{ 11, 9, 7, 5, 3, 1, 25, 23, 21, 19},
|
|
{ 17, 15, 13, 11, 9, 7, 5, 3, 1, 25},
|
|
{ 23, 21, 19, 17, 15, 13, 11, 9, 7, 5}
|
|
}, matrix.copyGrid());
|
|
}
|
|
|
|
//! multiply()
|
|
@Test
|
|
public void testMultiply_matrix_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.multiply((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testMultiply_matrix_manyRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.multiply(new ModMatrix(new int[][]{{0, 0}, {0, 0}, {0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testMultiply_matrix_fewRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.multiply(new ModMatrix(new int[][]{{0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testMultiply_matrix_square(){
|
|
ModMatrix mulMatrix = new ModMatrix(new int[][]{{1, 2}, {3, 4}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.multiply(mulMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{19, 16}, {11, 4}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testMultiply_matrix_rectangle(){
|
|
ModMatrix mulMatrix = new ModMatrix(new int[][]{{1, 2, 3}, {4, 5, 6}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.multiply(mulMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{17, 14, 11}, {7, 0, 19}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testMultiply_scalar(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.multiply(2);
|
|
|
|
assertArrayEquals(new int[][]{{24, 22}, {20, 18}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testMultiply_integerMatrix_square(){
|
|
IntegerMatrix mulMatrix = new IntegerMatrix(new int[][]{{1, 2}, {3, 4}});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.multiply(mulMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{19, 16}, {11, 4}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testMultiply_integerMatrix_rectangle(){
|
|
IntegerMatrix mulMatrix = new IntegerMatrix(new int[][]{{1, 2, 3}, {4, 5, 6}});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
matrix = matrix.multiply(mulMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{17, 14, 11}, {7, 0, 19}}, matrix.copyGrid());
|
|
}
|
|
|
|
//! pow
|
|
@Test
|
|
public void testPow_rectangle(){
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{1, 2, 3}, {4, 5, 6}}, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.pow(2);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testPow_negative(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidScalarException.class, () -> {
|
|
matrix.pow(-1);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testPow_0(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
ModMatrix result = matrix.pow(0);
|
|
|
|
assertEquals(new ModMatrix(2, 2, 1, MOD), result);
|
|
}
|
|
|
|
@Test
|
|
public void testPow_2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
ModMatrix result = matrix.pow(2);
|
|
|
|
assertEquals(new ModMatrix(new int[][]{{7, 10}, {15, 22}}, MOD), result);
|
|
}
|
|
|
|
@Test
|
|
public void testPow_3(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
ModMatrix result = matrix.pow(3);
|
|
|
|
assertEquals(new ModMatrix(new int[][]{{15, 24}, {23, 12}}, MOD), result);
|
|
}
|
|
|
|
//! dotProduct()
|
|
@Test
|
|
public void testDotProduct_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.dotProduct((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testDotProduct_fewRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.dotProduct(new ModMatrix(new int[][]{{0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testDotProduct_manyRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.dotProduct(new ModMatrix(new int[][]{{0, 0}, {0, 0}, {0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testDotProduct_size2(){
|
|
ModMatrix dotMatrix = new ModMatrix(new int[][]{{1, 2}, {3, 4}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
int result = matrix.dotProduct(dotMatrix);
|
|
|
|
assertEquals(24, result);
|
|
}
|
|
|
|
@Test
|
|
public void testDotProduct_size10(){
|
|
ModMatrix dotMatrix = new ModMatrix(new int[][]{
|
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
|
{11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
{21, 22, 23, 24, 25, 26, 27, 28, 29, 30},
|
|
{31, 32, 33, 34, 35, 36, 37, 38, 39, 40},
|
|
{41, 42, 43, 44, 45, 46, 47, 48, 49, 50},
|
|
{51, 52, 53, 54, 55, 56, 57, 58, 59, 60},
|
|
{61, 62, 63, 64, 65, 66, 67, 68, 69, 70},
|
|
{71, 72, 73, 74, 75, 76, 77, 78, 79, 80},
|
|
{81, 82, 83, 84, 85, 86, 87, 88, 89, 90},
|
|
{91, 92, 93, 94, 95, 96, 97, 98, 99, 100}
|
|
}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
int result = matrix.dotProduct(dotMatrix);
|
|
|
|
assertEquals(10, result);
|
|
}
|
|
|
|
@Test
|
|
public void testDotProduct_integerMatrix_size2(){
|
|
IntegerMatrix dotMatrix = new IntegerMatrix(new int[][]{{1, 2}, {3, 4}});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
int result = matrix.dotProduct(dotMatrix);
|
|
|
|
assertEquals(24, result);
|
|
}
|
|
|
|
@Test
|
|
public void testDotProduct_integerMatrix_size10(){
|
|
IntegerMatrix dotMatrix = new IntegerMatrix(new int[][]{
|
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
|
{11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
{21, 22, 23, 24, 25, 26, 27, 28, 29, 30},
|
|
{31, 32, 33, 34, 35, 36, 37, 38, 39, 40},
|
|
{41, 42, 43, 44, 45, 46, 47, 48, 49, 50},
|
|
{51, 52, 53, 54, 55, 56, 57, 58, 59, 60},
|
|
{61, 62, 63, 64, 65, 66, 67, 68, 69, 70},
|
|
{71, 72, 73, 74, 75, 76, 77, 78, 79, 80},
|
|
{81, 82, 83, 84, 85, 86, 87, 88, 89, 90},
|
|
{91, 92, 93, 94, 95, 96, 97, 98, 99, 100}
|
|
});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
int result = matrix.dotProduct(dotMatrix);
|
|
|
|
assertEquals(10, result);
|
|
}
|
|
|
|
//! hadamardProduct()
|
|
@Test
|
|
public void testHadamardProduct_nullMatrix(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(NullMatrixException.class, () -> {
|
|
matrix.hadamardProduct((ModMatrix)null);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_fewRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.hadamardProduct(new ModMatrix(new int[][]{{0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_manyRows(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.hadamardProduct(new ModMatrix(new int[][]{{0, 0}, {0, 0}, {0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_fewCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.hadamardProduct(new ModMatrix(new int[][]{{0}, {0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_manyCols(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
matrix.hadamardProduct(new ModMatrix(new int[][]{{0, 0, 0}, {0, 0, 0}}, MOD));
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_size2(){
|
|
ModMatrix hadMatrix = new ModMatrix(new int[][]{{1, 2}, {3, 4}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
ModMatrix result = matrix.hadamardProduct(hadMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{25, 22}, {17, 10}}, result.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_size10(){
|
|
ModMatrix hadMatrix = new ModMatrix(new int[][]{
|
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
|
{11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
{21, 22, 23, 24, 25, 26, 27, 28, 29, 30},
|
|
{31, 32, 33, 34, 35, 36, 37, 38, 39, 40},
|
|
{41, 42, 43, 44, 45, 46, 47, 48, 49, 50},
|
|
{51, 52, 53, 54, 55, 56, 57, 58, 59, 60},
|
|
{61, 62, 63, 64, 65, 66, 67, 68, 69, 70},
|
|
{71, 72, 73, 74, 75, 76, 77, 78, 79, 80},
|
|
{81, 82, 83, 84, 85, 86, 87, 88, 89, 90},
|
|
{91, 92, 93, 94, 95, 96, 97, 98, 99, 100}
|
|
}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
ModMatrix result = matrix.hadamardProduct(hadMatrix);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{25, 22, 17, 10, 1, 16, 3, 14, 23, 4},
|
|
{ 9, 12, 13, 12, 9, 4, 23, 14, 3, 16},
|
|
{ 1, 10, 17, 22, 25, 0, 25, 22, 17, 10},
|
|
{ 1, 16, 3, 14, 23, 4, 9, 12, 13, 12},
|
|
{ 9, 4, 23, 14, 3, 16, 1, 10, 17, 22},
|
|
{25, 0, 25, 22, 17, 10, 1, 16, 3, 14},
|
|
{23, 4, 9, 12, 13, 12, 9, 4, 23, 14},
|
|
{ 3, 16, 1, 10, 17, 22, 25, 0, 25, 22},
|
|
{17, 10, 1, 16, 3, 14, 23, 4, 9, 12},
|
|
{13, 12, 9, 4, 23, 14, 3, 16, 1, 10}
|
|
}, result.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_integerMatrix_size2(){
|
|
IntegerMatrix hadMatrix = new IntegerMatrix(new int[][]{{1, 2}, {3, 4}});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
ModMatrix result = matrix.hadamardProduct(hadMatrix);
|
|
|
|
assertArrayEquals(new int[][]{{25, 22}, {17, 10}}, result.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testHadamardProduct_integerMatrix_size10(){
|
|
IntegerMatrix hadMatrix = new IntegerMatrix(new int[][]{
|
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
|
{11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
|
{21, 22, 23, 24, 25, 26, 27, 28, 29, 30},
|
|
{31, 32, 33, 34, 35, 36, 37, 38, 39, 40},
|
|
{41, 42, 43, 44, 45, 46, 47, 48, 49, 50},
|
|
{51, 52, 53, 54, 55, 56, 57, 58, 59, 60},
|
|
{61, 62, 63, 64, 65, 66, 67, 68, 69, 70},
|
|
{71, 72, 73, 74, 75, 76, 77, 78, 79, 80},
|
|
{81, 82, 83, 84, 85, 86, 87, 88, 89, 90},
|
|
{91, 92, 93, 94, 95, 96, 97, 98, 99, 100}
|
|
});
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
ModMatrix result = matrix.hadamardProduct(hadMatrix);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{25, 22, 17, 10, 1, 16, 3, 14, 23, 4},
|
|
{ 9, 12, 13, 12, 9, 4, 23, 14, 3, 16},
|
|
{ 1, 10, 17, 22, 25, 0, 25, 22, 17, 10},
|
|
{ 1, 16, 3, 14, 23, 4, 9, 12, 13, 12},
|
|
{ 9, 4, 23, 14, 3, 16, 1, 10, 17, 22},
|
|
{25, 0, 25, 22, 17, 10, 1, 16, 3, 14},
|
|
{23, 4, 9, 12, 13, 12, 9, 4, 23, 14},
|
|
{ 3, 16, 1, 10, 17, 22, 25, 0, 25, 22},
|
|
{17, 10, 1, 16, 3, 14, 23, 4, 9, 12},
|
|
{13, 12, 9, 4, 23, 14, 3, 16, 1, 10}
|
|
}, result.copyGrid());
|
|
}
|
|
|
|
//! transpose()
|
|
@Test
|
|
public void testTranspose_size0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
ModMatrix result = matrix.transpose();
|
|
|
|
assertEquals(new ModMatrix(MOD), result);
|
|
}
|
|
|
|
@Test
|
|
public void testTranspose_size0x2(){
|
|
int[][] grid = new int[0][2];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertArrayEquals(new int[0][0], matrix.transpose().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testTranspose_size2x0(){
|
|
int[][] grid = new int[2][0];
|
|
ModMatrix matrix = new ModMatrix(grid, MOD);
|
|
|
|
assertArrayEquals(new int[0][0], matrix.transpose().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testTranspose_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertArrayEquals(new int[][]{{25, 23}, {24, 22}}, matrix.transpose().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testTranspose_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{25, 15, 5, 21, 11, 1, 17, 7, 23, 13},
|
|
{24, 14, 4, 20, 10, 0, 16, 6, 22, 12},
|
|
{23, 13, 3, 19, 9, 25, 15, 5, 21, 11},
|
|
{22, 12, 2, 18, 8, 24, 14, 4, 20, 10},
|
|
{21, 11, 1, 17, 7, 23, 13, 3, 19, 9},
|
|
{20, 10, 0, 16, 6, 22, 12, 2, 18, 8},
|
|
{19, 9, 25, 15, 5, 21, 11, 1, 17, 7},
|
|
{18, 8, 24, 14, 4, 20, 10, 0, 16, 6},
|
|
{17, 7, 23, 13, 3, 19, 9, 25, 15, 5},
|
|
{16, 6, 22, 12, 2, 18, 8, 24, 14, 4}
|
|
}, matrix.transpose().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testTranspose_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{25, 15},
|
|
{24, 14},
|
|
{23, 13},
|
|
{22, 12},
|
|
{21, 11},
|
|
{20, 10},
|
|
{19, 9},
|
|
{18, 8},
|
|
{17, 7},
|
|
{16, 6}
|
|
}, matrix.transpose().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testTranspose_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{25, 23, 21, 19, 17, 15, 13, 11, 9, 7},
|
|
{24, 22, 20, 18, 16, 14, 12, 10, 8, 6}
|
|
}, matrix.transpose().copyGrid());
|
|
}
|
|
|
|
//! determinant() / det()
|
|
@Test
|
|
public void testDeterminant_size0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::determinant);
|
|
assertThrows(InvalidGeometryException.class, matrix::det);
|
|
}
|
|
|
|
@Test
|
|
public void testDeterminant_size1(){
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{1}}, MOD);
|
|
|
|
assertEquals(1, matrix.determinant());
|
|
assertEquals(1, matrix.det());
|
|
}
|
|
|
|
@Test
|
|
public void testDeterminant_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertEquals(-2, matrix.determinant());
|
|
assertEquals(-2, matrix.det());
|
|
}
|
|
|
|
@Test
|
|
public void testDeterminant_size3(){
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{-1, -2, -3}, {-4, -5, -6}, {-7, -8, -9}}, MOD);
|
|
|
|
assertEquals(0, matrix.determinant());
|
|
assertEquals(0, matrix.det());
|
|
}
|
|
|
|
@Test
|
|
public void testDeterminant_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertEquals(0, matrix.determinant());
|
|
assertEquals(0, matrix.det());
|
|
}
|
|
|
|
@Test
|
|
public void testDeterminant_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::determinant);
|
|
assertThrows(InvalidGeometryException.class, matrix::det);
|
|
}
|
|
|
|
@Test
|
|
public void testDeterminant_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::determinant);
|
|
assertThrows(InvalidGeometryException.class, matrix::det);
|
|
}
|
|
|
|
//! cofactor() / cof()
|
|
@Test
|
|
public void testCofactor_size0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::cofactor);
|
|
assertThrows(InvalidGeometryException.class, matrix::cof);
|
|
}
|
|
|
|
@Test
|
|
public void testCofactor_size1(){
|
|
int[][] expectedGrid = new int[][]{{1}};
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{-1}}, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.cofactor().copyGrid());
|
|
assertArrayEquals(expectedGrid, matrix.cof().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCofactor_size2(){
|
|
int[][] expectedGrid = new int[][]{{22, 3}, {2, 25}};
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.cofactor().copyGrid());
|
|
assertArrayEquals(expectedGrid, matrix.cof().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCofactor_size10(){
|
|
int[][] expectedGrid = new int[][]{
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
};
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.cofactor().copyGrid());
|
|
assertArrayEquals(expectedGrid, matrix.cof().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testCofactor_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::cofactor);
|
|
assertThrows(InvalidGeometryException.class, matrix::cof);
|
|
}
|
|
|
|
@Test
|
|
public void testCofactor_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::cofactor);
|
|
assertThrows(InvalidGeometryException.class, matrix::cof);
|
|
}
|
|
|
|
//! adjoint() / adj()
|
|
@Test
|
|
public void testAdjoint_size0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::adjoint);
|
|
assertThrows(InvalidGeometryException.class, matrix::adj);
|
|
}
|
|
|
|
@Test
|
|
public void testAdjoint_size1(){
|
|
int[][] expectedGrid = new int[][]{{1}};
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{-1}}, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.adjoint().copyGrid());
|
|
assertArrayEquals(expectedGrid, matrix.adj().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAdjoint_size2(){
|
|
int[][] expectedGrid = new int[][]{{22, 2}, {3, 25}};
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.adjoint().copyGrid());
|
|
assertArrayEquals(expectedGrid, matrix.adj().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAdjoint_size10(){
|
|
int[][] expectedGrid = new int[][]{
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
|
};
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.adjoint().copyGrid());
|
|
assertArrayEquals(expectedGrid, matrix.adj().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testAdjoint_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::adjoint);
|
|
assertThrows(InvalidGeometryException.class, matrix::adj);
|
|
}
|
|
|
|
@Test
|
|
public void testAdjoint_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::adjoint);
|
|
assertThrows(InvalidGeometryException.class, matrix::adj);
|
|
}
|
|
|
|
//! inverse()
|
|
@Test
|
|
public void testInverse_size0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::inverse);
|
|
}
|
|
|
|
@Test
|
|
public void testInverse_size1(){
|
|
int[][] expectedGrid = new int[][]{{25}};
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{-1}}, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.inverse().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testInverse_size2(){
|
|
int[][] expectedGrid = new int[][]{{24, 3}, {3, 22}};
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{4, 3}, {3, 2}}, MOD);
|
|
|
|
assertArrayEquals(expectedGrid, matrix.inverse().copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testInverse_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertThrows(InvalidScalarException.class, matrix::inverse);
|
|
}
|
|
|
|
@Test
|
|
public void testInverse_size2x10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2x10, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::inverse);
|
|
}
|
|
|
|
@Test
|
|
public void testInverse_size10x2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10x2, MOD);
|
|
|
|
assertThrows(InvalidGeometryException.class, matrix::inverse);
|
|
}
|
|
|
|
//! equals()
|
|
@Test
|
|
public void testEquals_null(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertFalse(matrix.equals(null));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_matrixObject(){
|
|
ModMatrix equalsMatrix = new ModMatrix(negativeGrid2, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertTrue(matrix.equals((Object)equalsMatrix));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_array(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertTrue(matrix.equals(negativeGrid2));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_invalidType(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertFalse(matrix.equals(1));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_manyRows(){
|
|
ModMatrix equalsMatrix = new ModMatrix(new int[][]{{-1, -2}, {-3, -4}, {-5, -6}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertFalse(matrix.equals(equalsMatrix));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_fewRows(){
|
|
ModMatrix equalsMatrix = new ModMatrix(new int[][]{{-1, -2}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertFalse(matrix.equals(equalsMatrix));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_manyCols(){
|
|
ModMatrix equalsMatrix = new ModMatrix(new int[][]{{-1, -2, -3}, {-4, -5, -6}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertFalse(matrix.equals(equalsMatrix));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_fewCols(){
|
|
ModMatrix equalsMatrix = new ModMatrix(new int[][]{{-1}, {-2}}, MOD);
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertFalse(matrix.equals(equalsMatrix));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_notEquals(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
ModMatrix equalsMatrix = matrix.transpose();
|
|
|
|
assertFalse(matrix.equals(equalsMatrix));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_equals(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
ModMatrix equalsMatrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertTrue(matrix.equals(equalsMatrix));
|
|
}
|
|
|
|
@Test
|
|
public void testEquals_self(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertTrue(matrix.equals(matrix));
|
|
}
|
|
|
|
//! hashCode()
|
|
@Test
|
|
public void testHashCode_size0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertEquals(Arrays.hashCode(matrix.grid), matrix.hashCode());
|
|
}
|
|
|
|
@Test
|
|
public void testHashCode_size1(){
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{1}}, MOD);
|
|
|
|
assertEquals(Arrays.hashCode(matrix.grid), matrix.hashCode());
|
|
}
|
|
|
|
@Test
|
|
public void testHashCode_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertEquals(Arrays.hashCode(matrix.grid), matrix.hashCode());
|
|
}
|
|
|
|
@Test
|
|
public void testHashCode_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertEquals(Arrays.hashCode(matrix.grid), matrix.hashCode());
|
|
}
|
|
|
|
//! toString()
|
|
@Test
|
|
public void testToString_size0(){
|
|
ModMatrix matrix = new ModMatrix(MOD);
|
|
|
|
assertEquals("[]\nmod(26)", matrix.toString());
|
|
}
|
|
|
|
@Test
|
|
public void testToString_size1(){
|
|
ModMatrix matrix = new ModMatrix(new int[][]{{1}}, MOD);
|
|
|
|
assertEquals("[1]\nmod(26)", matrix.toString());
|
|
}
|
|
|
|
@Test
|
|
public void testToString_size2(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid2, MOD);
|
|
|
|
assertEquals("[25, 24]\n[23, 22]\nmod(26)", matrix.toString());
|
|
}
|
|
|
|
@Test
|
|
public void testToString_size10(){
|
|
ModMatrix matrix = new ModMatrix(negativeGrid10, MOD);
|
|
|
|
assertEquals(
|
|
"""
|
|
[25, 24, 23, 22, 21, 20, 19, 18, 17, 16]
|
|
[15, 14, 13, 12, 11, 10, 9, 8, 7, 6]
|
|
[5, 4, 3, 2, 1, 0, 25, 24, 23, 22]
|
|
[21, 20, 19, 18, 17, 16, 15, 14, 13, 12]
|
|
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
|
|
[1, 0, 25, 24, 23, 22, 21, 20, 19, 18]
|
|
[17, 16, 15, 14, 13, 12, 11, 10, 9, 8]
|
|
[7, 6, 5, 4, 3, 2, 1, 0, 25, 24]
|
|
[23, 22, 21, 20, 19, 18, 17, 16, 15, 14]
|
|
[13, 12, 11, 10, 9, 8, 7, 6, 5, 4]
|
|
mod(26)""",
|
|
matrix.toString());
|
|
}
|
|
|
|
//! generateIdentity()
|
|
@Test
|
|
public void testGenerateIdentity_size0(){
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
ModMatrix.generateIdentity(0);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGenerateIdentity_negativeSize(){
|
|
assertThrows(InvalidGeometryException.class, () -> {
|
|
ModMatrix.generateIdentity(-1);
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void testGenerateIdentity_size2(){
|
|
ModMatrix matrix = ModMatrix.generateIdentity(2);
|
|
|
|
assertArrayEquals(new int[][]{{1, 0}, {0, 1}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testGenerateIdentity_size3(){
|
|
ModMatrix matrix = ModMatrix.generateIdentity(3);
|
|
|
|
assertArrayEquals(new int[][]{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, matrix.copyGrid());
|
|
}
|
|
|
|
@Test
|
|
public void testGenerateIdentity_size10(){
|
|
ModMatrix matrix = ModMatrix.generateIdentity(10);
|
|
|
|
assertArrayEquals(new int[][]{
|
|
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 1, 0, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 1, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
|
|
}, matrix.copyGrid());
|
|
}
|
|
}
|