Created DoubleMatrix

This commit is contained in:
2022-02-07 22:33:11 +00:00
parent a4d419c1ab
commit 8fcbc054f2

View File

@@ -0,0 +1,688 @@
//Matrix/src/test/java/com/mattrixwv/matrix/TestDoubleMatrix.java
//Mattrixwv
// Created: 02-07-22
//Modified: 02-07-22
package com.mattrixwv.matrix;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class TestDoubleMatrix{
//Grid 1x1
private static final double[][] grid1 = {
{0.5}
};
private static final double[][] transformGrid1_1 = {
{0.5}
};
private static final double[][] transformGrid1_2 = {
{1.5}
};
//Grid 2x2
private static final double[][] grid2 = {
{0.5, 1.5},
{0.5, 1.5}
};
private static final double[][] transformGrid2_1 = {
{0.5, 0},
{0.5, 0}
};
private static final double[][] transformGrid2_2 = {
{1.5, 2.5},
{1.5, 2.5}
};
//Grid 3x3
private static final double[][] grid3 = {
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5}
};
private static final double[][] transformGrid3_1 = {
{1.5, 0.5, 0},
{1.5, 0.5, 0},
{1.5, 0.5, 0}
};
private static final double[][] transformGrid3_2 = {
{1.5, 2.5, 3.5},
{1.5, 2.5, 3.5},
{1.5, 2.5, 3.5}
};
//Grid 4x4
private static final double[][] grid4 = {
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5}
};
private static final double[][] transformGrid4_1 = {
{2.5, 1.5, 0.5, 0},
{2.5, 1.5, 0.5, 0},
{2.5, 1.5, 0.5, 0},
{2.5, 1.5, 0.5, 0}
};
private static final double[][] transformGrid4_2 = {
{2.5, 1.5, 0.5, 0},
{2.5, 1.5, 0.5, 0},
{2.5, 1.5, 0.5, 0},
{2.5, 1.5, 0.5, 0}
};
//Grid 10x10
private static final double[][] grid10 = {
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}
};
private static final double[][] transformGrid10_1 = {
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0},
{8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5, 0}
};
private static final double[][] transformGrid10_2 = {
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5}
};
@Test
public void testEquals(){
//1x1
DoubleMatrix matrix = new DoubleMatrix(grid1);
assertTrue("DoubleMatrix 1x1 failed equals DoubleMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals = matrix.equals(grid1);
assertTrue("DoubleMatrix 1x1 failed equals double[][]", gridEquals);
//2x2
matrix = new DoubleMatrix(grid2);
assertTrue("DoubleMatrix 2x2 failed equals DoubleMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals2 = matrix.equals(grid2);
assertTrue("DoubleMatrix 2x2 failed equals double[][]", gridEquals2);
//3x3
matrix = new DoubleMatrix(grid3);
assertTrue("DoubleMatrix 3x3 failed equals DoubleMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals3 = matrix.equals(grid3);
assertTrue("DoubleMatrix 3x3 failed equals double[][]", gridEquals3);
//4x4
matrix = new DoubleMatrix(grid4);
assertTrue("DoubleMatrix 4x4 failed equals DoubleMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals4 = matrix.equals(grid4);
assertTrue("DoubleMatrix 4x4 failed equals double[][]", gridEquals4);
//10x10
matrix = new DoubleMatrix(grid10);
assertTrue("DoubleMatrix 10x10 failed equals DoubleMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals10 = matrix.equals(grid10);
assertTrue("DoubleMatrix 10x10 failed equals double[][]", gridEquals10);
}
@Test
public void testGets(){
//1x1
DoubleMatrix matrix = new DoubleMatrix(grid1);
assertEquals("DoubleMatrix 1x1 failed get", 0.5, matrix.get(0, 0), 0.0000001);
//GetRow
DoubleMatrix correctMatrix = new DoubleMatrix(new double[][]{{0.5}});
assertEquals("DoubleMatrix 1x1 failed getRow", correctMatrix, matrix.getRow(0));
//2x2
matrix = new DoubleMatrix(grid2);
assertEquals("DoubleMatrix 2x2 failed get", 0.5, matrix.get(0, 0), 0.0000001);
//GetRow
correctMatrix = new DoubleMatrix(new double[][]{{0.5, 1.5}});
assertEquals("DoubleMatrix 2x2 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new DoubleMatrix(new double[][]{
{0.5},
{0.5}
});
assertEquals("DoubleMatrix 2x2 failed getCol", correctMatrix, matrix.getCol(0));
//3x3
matrix = new DoubleMatrix(grid3);
assertEquals("DoubleMatrix 3x3 failed get", 0.5, matrix.get(0, 0), 0.0000001);
//GetRow
correctMatrix = new DoubleMatrix(new double[][]{{0.5, 1.5, 2.5}});
assertEquals("DoubleMatrix 3x3 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new DoubleMatrix(new double[][]{
{0.5},
{0.5},
{0.5}
});
assertEquals("DoubleMatrix 3x3 failed getCol", correctMatrix, matrix.getCol(0));
//4x4
matrix = new DoubleMatrix(grid4);
assertEquals("DoubleMatrix 4x4 failed get", 0.5, matrix.get(0, 0), 0.0000001);
//GetRow
correctMatrix = new DoubleMatrix(new double[][]{{0.5, 1.5, 2.5, 3.5}});
assertEquals("DoubleMatrix 4x4 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new DoubleMatrix(new double[][]{
{0.5},
{0.5},
{0.5},
{0.5}
});
assertEquals("DoubleMatrix 4x4 failed getCol", correctMatrix, matrix.getCol(0));
//10x10
matrix = new DoubleMatrix(grid10);
assertEquals("DoubleMatrix 10x10 failed get", 0.5, matrix.get(0, 0), 0.0000001);
//GetRow
correctMatrix = new DoubleMatrix(new double[][]{{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}});
assertEquals("DoubleMatrix 10x10 failed getRow", correctMatrix, matrix.getRow(0));
//GetCol
correctMatrix = new DoubleMatrix(new double[][]{
{0.5},
{0.5},
{0.5},
{0.5},
{0.5},
{0.5},
{0.5},
{0.5},
{0.5},
{0.5}
});
assertEquals("DoubleMatrix 10x10 failed getCol", correctMatrix, matrix.getCol(0));
}
@Test
public void testSets(){
//1x1
//Set
DoubleMatrix matrix = new DoubleMatrix(grid1);
matrix.set(0, 0, 1.5);
DoubleMatrix correctMatrix = new DoubleMatrix(new double[][]{{1.5}});
assertEquals("DoubleMatrix 1x1 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new double[]{0.0});
correctMatrix = new DoubleMatrix(new double[][]{{0.0}});
assertEquals("DoubleMatrix 1x1 failed setRow", correctMatrix, matrix);
//SetCol
matrix.setCol(0, new double[]{0.5});
correctMatrix = new DoubleMatrix(new double[][]{{0.5}});
assertEquals("DoubleMatrix 1x1 failed setCol", correctMatrix, matrix);
//2x2
//Set
matrix = new DoubleMatrix(grid2);
matrix.set(0, 0, 2.5);
correctMatrix = new DoubleMatrix(new double[][]{
{2.5, 1.5},
{0.5, 1.5}
});
assertEquals("DoubleMatrix 2x2 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(1, new double[]{1.5, 0.5});
correctMatrix = new DoubleMatrix(new double[][]{
{2.5, 1.5},
{1.5, 0.5}
});
assertEquals("DoubleMatrix 2x2 failed setRow", correctMatrix, matrix);
//SetCol
matrix = new DoubleMatrix(grid2);
matrix.setCol(0, new double[]{2.5, 2.5});
correctMatrix = new DoubleMatrix(new double[][]{
{2.5, 1.5},
{2.5, 1.5}
});
assertEquals("DoubleMatrix 2x2 failed setCol", correctMatrix, matrix);
//3x3
//Set
matrix = new DoubleMatrix(grid3);
matrix.set(0, 0, 2.5);
correctMatrix = new DoubleMatrix(new double[][]{
{2.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5}
});
assertEquals("DoubleMatrix 3x3 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new double[]{0, 0.5, 1.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0, 0.5, 1.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5}
});
assertEquals("DoubleMatrix 3x3 failed setRow", correctMatrix, matrix);
//SetCol
matrix.setCol(0, new double[]{0, 0, 0});
correctMatrix = new DoubleMatrix(new double[][]{
{0.0, 0.5, 1.5},
{0.0, 1.5, 2.5},
{0.0, 1.5, 2.5}
});
assertEquals("DoubleMatrix 3x3 failed setCol", correctMatrix, matrix);
//4x4
//Set
matrix = new DoubleMatrix(grid4);
matrix.set(0, 0, 2.5);
correctMatrix = new DoubleMatrix(new double[][]{
{2.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5}
});
assertEquals("DoubleMatrix 4x4 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new double[]{3.5, 2.5, 1.5, 0.5});
correctMatrix = new DoubleMatrix(new double[][]{
{3.5, 2.5, 1.5, 0.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5}
});
assertEquals("DoubleMatrix 4x4 failed setRow", correctMatrix, matrix);
//SetCol
matrix.setCol(0, new double[]{0, 0, 0, 0});
correctMatrix = new DoubleMatrix(new double[][]{
{0.0, 2.5, 1.5, 0.5},
{0.0, 1.5, 2.5, 3.5},
{0.0, 1.5, 2.5, 3.5},
{0.0, 1.5, 2.5, 3.5}
});
//10x10
//Set
matrix = new DoubleMatrix(grid10);
matrix.set(0, 0, 2.5);
correctMatrix = new DoubleMatrix(new double[][]{
{2.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}
});
assertEquals("DoubleMatrix 10x10 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new double[]{9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5});
correctMatrix = new DoubleMatrix(new double[][]{
{9.5, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}
});
assertEquals("DoubleMatrix 10x10 failed set", correctMatrix, matrix);
//SetCol
matrix.setCol(0, new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
correctMatrix = new DoubleMatrix(new double[][]{
{0.0, 8.5, 7.5, 6.5, 5.5, 4.5, 3.5, 2.5, 1.5, 0.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.0, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}
});
assertEquals("DoubleMatrix 10x10 failed setCol", correctMatrix, matrix);
}
@Test
public void testAdds(){
//1x1
//AddRow
DoubleMatrix matrix = new DoubleMatrix(grid1);
matrix.addRow(new double[]{0.5});
DoubleMatrix correctMatrix = new DoubleMatrix(new double[][]{{0.5}, {0.5}});
assertEquals("DoubleMatrix 1x1 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new DoubleMatrix(grid1);
matrix.addCol(new double[]{0.5});
correctMatrix = new DoubleMatrix(new double[][]{{0.5, 0.5}});
assertEquals("DoubleMatrix 1x1 failed addCol", correctMatrix, matrix);
//2x2
//AddRow
matrix = new DoubleMatrix(grid2);
matrix.addRow(new double[]{0.5, 1.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5},
{0.5, 1.5},
{0.5, 1.5}
});
assertEquals("DoubleMatrix 2x2 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new DoubleMatrix(grid2);
matrix.addCol(new double[]{2.5, 2.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5}
});
assertEquals("DoubleMatrix 2x2 failed addCol", correctMatrix, matrix);
//3x3
//AddRow
matrix = new DoubleMatrix(grid3);
matrix.addRow(new double[]{0.5, 1.5, 2.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5}
});
assertEquals("DoubleMatrix 3x3 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new DoubleMatrix(grid3);
matrix.addCol(new double[]{3.5, 3.5, 3.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5}
});
assertEquals("DoubleMatrix 3x3 failed addCol", correctMatrix, matrix);
//4x4
//AddRow
matrix = new DoubleMatrix(grid4);
matrix.addRow(new double[]{0.5, 1.5, 2.5, 3.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5}
});
assertEquals("DoubleMatrix 4x4 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new DoubleMatrix(grid4);
matrix.addCol(new double[]{4.5, 4.5, 4.5, 4.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5, 4.5},
{0.5, 1.5, 2.5, 3.5, 4.5},
{0.5, 1.5, 2.5, 3.5, 4.5},
{0.5, 1.5, 2.5, 3.5, 4.5}
});
assertEquals("DoubleMatrix 4x4 failed addCol", correctMatrix, matrix);
//10x10
//AddRow
matrix = new DoubleMatrix(grid10);
matrix.addRow(new double[]{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}
});
assertEquals("DoubleMatrix 10x10 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new DoubleMatrix(grid10);
matrix.addCol(new double[]{10.5, 10.5, 10.5, 10.5, 10.5, 10.5, 10.5, 10.5, 10.5, 10.5});
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5}
});
assertEquals("DoubleMatrix 10x10 failed addCol", correctMatrix, matrix);
}
@Test
public void testAppends(){
//1x1
//appendRight
DoubleMatrix matrix = new DoubleMatrix(grid1);
DoubleMatrix secondMatrix = new DoubleMatrix(grid1);
DoubleMatrix correctMatrix = new DoubleMatrix(new double[][]{{0.5, 0.5}});
assertEquals("DoubleMatrix 1x1 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new DoubleMatrix(new double[][]{
{0.5},
{0.5}
});
assertEquals("DoubleMatrix 1x1 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//2x2
//appendRight
matrix = new DoubleMatrix(grid2);
secondMatrix = new DoubleMatrix(grid2);
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 0.5, 1.5},
{0.5, 1.5, 0.5, 1.5}
});
assertEquals("DoubleMatrix 2x2 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5},
{0.5, 1.5},
{0.5, 1.5},
{0.5, 1.5}
});
assertEquals("DoubleMatrix 2x2 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//3x3
//appendRight
matrix = new DoubleMatrix(grid3);
secondMatrix = new DoubleMatrix(grid3);
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 0.5, 1.5, 2.5},
{0.5, 1.5, 2.5, 0.5, 1.5, 2.5},
{0.5, 1.5, 2.5, 0.5, 1.5, 2.5}
});
assertEquals("DoubleMatrix 3x3 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5},
{0.5, 1.5, 2.5}
});
assertEquals("DoubleMatrix 3x3 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//4x4
//appendRight
matrix = new DoubleMatrix(grid4);
secondMatrix = new DoubleMatrix(grid4);
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5, 0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5, 0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5, 0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5, 0.5, 1.5, 2.5, 3.5}
});
assertEquals("DoubleMatrix 4x4 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5},
{0.5, 1.5, 2.5, 3.5}
});
assertEquals("DoubleMatrix 4x4 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
//10x10
//appendRight
matrix = new DoubleMatrix(grid10);
secondMatrix = new DoubleMatrix(grid10);
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}
});
assertEquals("DoubleMatrix 10x10 failed appendRight", correctMatrix, matrix.appendRight(secondMatrix));
//appendBottom
correctMatrix = new DoubleMatrix(new double[][]{
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5},
{0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}, {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}
});
assertEquals("DoubleMatrix 10x10 failed appendBottom", correctMatrix, matrix.appendBottom(secondMatrix));
}
@Test
public void testAddition(){
//1x1
DoubleMatrix matrix = new DoubleMatrix(grid1);
DoubleMatrix transformMatrix = new DoubleMatrix(transformGrid1_1);
DoubleMatrix correctMatrix = new DoubleMatrix(new double[][]{{1.0}});
assertEquals("DoubleMatrix 1x1 failed add DoubleMatrix", correctMatrix, matrix.add(transformMatrix));
assertEquals("DoubleMatrix 1x1 failed add scalar", correctMatrix, matrix.add(0.5));
//2x2
matrix = new DoubleMatrix(grid2);
transformMatrix = new DoubleMatrix(transformGrid2_1);
correctMatrix = new DoubleMatrix(new double[][]{
{1.0, 1.5},
{1.0, 1.5}
});
assertEquals("DoubleMatrix 1x1 failed add DoubleMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new DoubleMatrix(new double[][]{
{1.0, 2.0},
{1.0, 2.0}
});
assertEquals("DoubleMatrix 2x2 failed add scalar", correctMatrix, matrix.add(0.5));
//3x3
matrix = new DoubleMatrix(grid3);
transformMatrix = new DoubleMatrix(transformGrid3_1);
correctMatrix = new DoubleMatrix(new double[][]{
{2.0, 2.0, 2.5},
{2.0, 2.0, 2.5},
{2.0, 2.0, 2.5}
});
assertEquals("DoubleMatrix 3x3 failed add DoubleMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new DoubleMatrix(new double[][]{
{1.0, 2.0, 3.0},
{1.0, 2.0, 3.0},
{1.0, 2.0, 3.0}
});
assertEquals("DoubleMatrix 3x3 failed add scalar", correctMatrix, matrix.add(0.5));
//4x4
matrix = new DoubleMatrix(grid4);
transformMatrix = new DoubleMatrix(transformGrid4_1);
correctMatrix = new DoubleMatrix(new double[][]{
{3.0, 3.0, 3.0, 3.5},
{3.0, 3.0, 3.0, 3.5},
{3.0, 3.0, 3.0, 3.5},
{3.0, 3.0, 3.0, 3.5}
});
assertEquals("DoubleMatrix 4x4 failed add DoubleMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new DoubleMatrix(new double[][]{
{1.0, 2.0, 3.0, 4.0},
{1.0, 2.0, 3.0, 4.0},
{1.0, 2.0, 3.0, 4.0},
{1.0, 2.0, 3.0, 4.0}
});
assertEquals("DoubleMatrix 4x4 failed add scalar", correctMatrix, matrix.add(0.5));
//10x10
matrix = new DoubleMatrix(grid10);
transformMatrix = new DoubleMatrix(transformGrid10_1);
correctMatrix = new DoubleMatrix(new double[][]{
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5},
{9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.5}
});
assertEquals("DoubleMatrix 10x10 failed add DoubleMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new DoubleMatrix(new double[][]{
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0},
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}
});
assertEquals("DoubleMatrix 10x10 failed add scalar", correctMatrix, matrix.add(0.5));
}
@Test
public void testSubtraction(){
}
@Test
public void testMultiplication(){
}
}