TestIntegerMatrix.java edited online with Bitbucket

This commit is contained in:
2022-02-03 19:44:22 +00:00
parent d26214f562
commit 8f09e321f1

View File

@@ -152,7 +152,7 @@ public class TestIntegerMatrix{
}
@Test
public void testGetsSetsAdds(){
public void testGets(){
//1x1
IntegerMatrix matrix = new IntegerMatrix(grid1);
assertEquals("IntegerMatrix 1x1 failed get", 1, matrix.get(0, 0));
@@ -162,7 +162,77 @@ public class TestIntegerMatrix{
//GetColumn
correctMatrix = new IntegerMatrix(new int[][]{{1}});
assertEquals("IntegerMatrix 1x1 failed getColumn", correctMatrix, matrix.getCol(0));
//2x2
matrix = new IntegerMatrix(grid2);
assertEquals("IntegerMatrix 2x2 failed get", 1, matrix.get(0, 0));
//GetRow
correctMatrix = new IntegerMatrix(new int[][]{{1, 2}});
assertEquals("IntegerMatrix 2x2 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new IntegerMatrix(new int[][]{
{1},
{1}
});
assertEquals("IntegerMatrix 2x2 failed getColumns", correctMatrix, matrix.getCol(0));
//3x3
matrix = new IntegerMatrix(grid3);
assertEquals("IntegerMatrix 3x3 failed get", 1, matrix.get(0, 0));
//GetRow
correctMatrix = new IntegerMatrix(new int[][]{{1, 2, 3}});
assertEquals("IntegerMatrix 3x3 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new IntegerMatrix(new int[][]{
{1},
{1},
{1}
});
assertEquals("IntegerMatrix 3x3 failed getCol", correctMatrix, matrix.getCol(0));
//4x4
matrix = new IntegerMatrix(grid4);
assertEquals("IntegerMatrix 4x4 failed get", 1, matrix.get(0, 0));
//GetRow
correctMatrix = new IntegerMatrix(new int[][]{{1, 2, 3, 4}});
assertEquals("IntegerMatrix 4x4 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new IntegerMatrix(new int[][]{
{1},
{1},
{1},
{1}
});
assertEquals("IntegerMatrix 4x4 failed getCol", correctMatrix, matrix.getCol(0));
//10x10
matrix = new IntegerMatrix(grid10);
assertEquals("IntegerMatrix 10x10 failed get", 1, matrix.get(0, 0));
//GetRow
correctMatrix = new IntegerMatrix(new int[][]{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}});
assertEquals("IntegerMatrix 10x10 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new IntegerMatrix(new int[][]{
{1},
{1},
{1},
{1},
{1},
{1},
{1},
{1},
{1},
{1}
});
assertEquals("IntegerMatrix 10x10 failed getColumn", correctMatrix, matrix.getCol(0));
}
@Test
public void testSets(){
//1x1
//Set
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix correctMatrix = null;
matrix.set(0, 0, 2);
correctMatrix = new IntegerMatrix(new int[][]{{2}});
assertEquals("IntegerMatrix 1x1 failed set", correctMatrix, matrix);
@@ -174,7 +244,144 @@ public class TestIntegerMatrix{
matrix.setCol(0, new int[]{1});
correctMatrix = new IntegerMatrix(new int[][]{{1}});
assertEquals("IntegerMatrix 1x1 failed setCol", correctMatrix, matrix);
//2x2
//Set
matrix = new IntegerMatrix(grid2);
matrix.set(0, 0, 3);
correctMatrix = new IntegerMatrix(new int[][]{
{3, 2},
{1, 2}
});
assertEquals("IntegerMatrix 2x2 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(1, new int[]{2, 1});
correctMatrix = new IntegerMatrix(new int[][]{
{3, 2},
{2, 1}
});
assertEquals("IntegerMatrix 2x2 failed set row", correctMatrix, matrix);
//SetColumn
matrix = new IntegerMatrix(grid2);
matrix.setCol(0, new int[]{3, 3});
correctMatrix = new IntegerMatrix(new int[][]{
{3, 2},
{3, 2}
});
assertEquals("IntegerMatrix 2x2 failed set row", correctMatrix, matrix);
//3x3
//Set
matrix = new IntegerMatrix(grid3);
matrix.set(0, 0, 3);
correctMatrix = new IntegerMatrix(new int[][]{
{3, 2, 3},
{1, 2, 3},
{1, 2, 3},
});
assertEquals("IntegerMatrix 3x3 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new int[]{0, 1, 2});
correctMatrix = new IntegerMatrix(new int[][]{
{0, 1, 2},
{1, 2, 3},
{1, 2, 3}
});
assertEquals("IntegerMatrix 3x3 failed setRow", correctMatrix, matrix);
//SetColumn
matrix.setCol(0, new int[]{0, 0, 0});
correctMatrix = new IntegerMatrix(new int[][]{
{0, 1, 2},
{0, 2, 3},
{0, 2, 3}
});
assertEquals("IntegerMatrix 3x3 failed setColumn", correctMatrix, matrix);
//4x4
//Set
matrix = new IntegerMatrix(grid4);
matrix.set(0, 0, 3);
correctMatrix = new IntegerMatrix(new int[][]{
{3, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
});
assertEquals("IntegerMatrix 4x4 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new int[]{4, 3, 2, 1});
correctMatrix = new IntegerMatrix(new int[][]{
{4, 3, 2, 1},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
});
assertEquals("IntegerMatrix 4x4 failed setRow", correctMatrix, matrix);
//SetColumn
matrix.setCol(0, new int[]{0, 0, 0, 0});
correctMatrix = new IntegerMatrix(new int[][]{
{0, 3, 2, 1},
{0, 2, 3, 4},
{0, 2, 3, 4},
{0, 2, 3, 4}
});
assertEquals("IntegerMatrix 4x4 failed setCol", correctMatrix, matrix);
//10x10
//Set
matrix = new IntegerMatrix(grid10);
matrix.set(0, 0, 3);
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 10x10 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 10x10 failed setRow", correctMatrix, matrix);
//SetColumn
matrix.setCol(0, new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0});
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 10x10 failed setColumn", correctMatrix, matrix);
}
@Test
public void testAdds(){
//1x1
//AddRow
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix correctMatrix = null;
matrix.addRow(new int[]{1});
correctMatrix = new IntegerMatrix(new int[][]{{1}, {1}});
assertEquals("IntegerMatrix 1x1 failed addRow", correctMatrix, matrix);
@@ -184,53 +391,214 @@ public class TestIntegerMatrix{
correctMatrix = new IntegerMatrix(new int[][]{{1, 1}});
assertEquals("IntegerMatrix 1x1 failed addCol", correctMatrix, matrix);
//2x2
matrix = new IntegerMatrix(grid2);
assertEquals("IntegerMatrix 2x2 failed get", 1, matrix.get(0, 0));
//GetRow
//GetColumn
//Set
//SetRow
//SetColumn
//AddRow
matrix = new IntegerMatrix(grid2);
matrix.addRow(new int[]{1, 2});
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2},
{1, 2},
{1, 2}
});
assertEquals("IntegerMatrix 2x2 failed set row", correctMatrix, matrix);
//AddColumn
matrix = new IntegerMatrix(grid2);
matrix.addCol(new int[]{3, 3});
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2, 3},
{1, 2, 3}
});
assertEquals("IntegerMatrix 2x2 failed set row", correctMatrix, matrix);
//3x3
matrix = new IntegerMatrix(grid3);
assertEquals("IntegerMatrix 3x3 failed get", 1, matrix.get(0, 0));
//GetRow
//GetColumn
//Set
//SetRow
//SetColumn
//AddRow
matrix = new IntegerMatrix(grid3);
matrix.addRow(new int[]{1, 2, 3});
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2, 3},
{1, 2, 3},
{1, 2, 3},
{1, 2, 3}
});
assertEquals("IntegerMatrix 3x3 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new IntegerMatrix(grid3);
matrix.addCol(new int[]{4, 4, 4});
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
});
assertEquals("IntegerMatrix 3x3 failed addCol", correctMatrix, matrix);
//4x4
matrix = new IntegerMatrix(grid4);
assertEquals("IntegerMatrix 4x4 failed get", 1, matrix.get(0, 0));
//GetRow
//GetColumn
//Set
//SetRow
//SetColumn
//AddRow
matrix = new IntegerMatrix(grid4);
matrix.addRow(new int[]{1, 2, 3, 4});
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
});
assertEquals("IntegerMatrix 4x4 failed addRow", correctMatrix, matrix);
//AddColumn
matrix.addCol(new int[]{5, 5, 5, 5, 5});
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 4x4 failed addCol", correctMatrix, matrix);
//10x10
matrix = new IntegerMatrix(grid10);
assertEquals("IntegerMatrix 10x10 failed get", 1, matrix.get(0, 0));
//GetRow
//GetColumn
//Set
//SetRow
//SetColumn
//AddRow
matrix = new IntegerMatrix(grid10);
matrix.addRow(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 10x10 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new IntegerMatrix(grid10);
matrix.addCol(new int[]{11, 11, 11, 11, 11, 11, 11, 11, 11, 11});
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 10x10 failed addColumn", correctMatrix, matrix);
}
@Test
public void testAppends(){
//1x1
//appendRight
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix secondMatrix = new IntegerMatrix(grid1);
IntegerMatrix correctMatrix = new IntegerMatrix(new int[][]{{1, 1}});
assertEquals("IntegerMatrix 1x1 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new IntegerMatrix(new int[][]{
{1},
{1}
});
assertEquals("IntegerMatrix 1x1 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//2x2
//appendRight
matrix = new IntegerMatrix(grid2);
secondMatrix = new IntegerMatrix(grid2);
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2, 1, 2},
{1, 2, 1, 2}
});
assertEquals("IntegerMatrix 2x2 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2},
{1, 2},
{1, 2},
{1, 2}
});
assertEquals("IntegerMatrix 2x2 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//3x3
//appendRight
matrix = new IntegerMatrix(grid3);
secondMatrix = new IntegerMatrix(grid3);
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2, 3, 1, 2, 3},
{1, 2, 3, 1, 2, 3},
{1, 2, 3, 1, 2, 3}
});
assertEquals("IntegerMatrix 3x3 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new IntegerMatrix(new int[][]{
{1, 2, 3},
{1, 2, 3},
{1, 2, 3},
{1, 2, 3},
{1, 2, 3},
{1, 2, 3}
});
assertEquals("IntegerMatrix 3x3 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//4x4
//appendRight
matrix = new IntegerMatrix(grid4);
secondMatrix = new IntegerMatrix(grid4);
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 4x4 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 4x4 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//10x10
//appendRight
matrix = new IntegerMatrix(grid10);
secondMatrix = new IntegerMatrix(grid10);
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 10x10 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new IntegerMatrix(new int[][]{
{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("IntegerMatrix 10x10 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
}
@Test