Added start of integer matrix

This commit is contained in:
2022-02-02 22:10:46 -05:00
parent e5efca7056
commit b5bfbf71f4
6 changed files with 1246 additions and 0 deletions

View File

@@ -0,0 +1,643 @@
//Matrix/src/test/java/com/mattrixwv/matrix/TestIntegerMatrix.java
//Mattrixwv
// Created: 02-01-22
//Modified: 02-02-22
package com.mattrixwv.matrix;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class TestIntegerMatrix{
//Grid 1x1
private static final int[][] grid1 = {
{1}
};
private static final int[][] transformGrid1_1 = {
{1}
};
private static final int[][] transformGrid1_2 = {
{2}
};
//Grid 2x2
private static final int[][] grid2 = {
{1, 2},
{1, 2}
};
private static final int[][] transformGrid2_1 = {
{1, 0},
{1, 0}
};
private static final int[][] transformGrid2_2 = {
{2, 3},
{2, 3}
};
//Grid 3x3
private static final int[][] grid3 = {
{1, 2, 3},
{1, 2, 3},
{1, 2, 3}
};
private static final int[][] transformGrid3_1 = {
{2, 1, 0},
{2, 1, 0},
{2, 1, 0}
};
private static final int[][] transformGrid3_2 = {
{2, 3, 4},
{2, 3, 4},
{2, 3, 4}
};
//Grid 4x4
private static final int[][] grid4 = {
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
};
private static final int[][] transformGrid4_1 = {
{3, 2, 1, 0},
{3, 2, 1, 0},
{3, 2, 1, 0},
{3, 2, 1, 0}
};
private static final int[][] transformGrid4_2 = {
{2, 3, 4, 5},
{2, 3, 4, 5},
{2, 3, 4, 5},
{2, 3, 4, 5}
};
//Grid 10x10
private static final int[][] grid10 = {
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
};
private static final int[][] transformGrid10_1 = {
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
};
private static final int[][] transformGrid10_2 = {
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
};
@Test
public void testEquals(){
//1x1;
IntegerMatrix matrix = new IntegerMatrix(grid1);
assertTrue("IntegerMatrix 1x1 failed equals IntegerMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals = matrix.equals(grid1);
assertTrue("IntegerMatrix 1x1 failed equals int[][]", gridEquals);
//2x2
matrix = new IntegerMatrix(grid2);
assertTrue("IntegerMatrix 2x2 failed equals IntegerMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals2 = matrix.equals(grid2);
assertTrue("IntegerMatrix 2x2 failed equals int[][]", gridEquals2);
//3x3
matrix = new IntegerMatrix(grid3);
assertTrue("IntegerMatrix 3x3 failed equals IntegerMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals3 = matrix.equals(grid3);
assertTrue("IntegerMatrix 3x3 failed equals int[][]", gridEquals3);
//4x4
matrix = new IntegerMatrix(grid4);
assertTrue("IntegerMatrix 4x4 failed equals IntegerMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals4 = matrix.equals(grid4);
assertTrue("IntegerMatrix 4x4 failed equals int[][]", gridEquals4);
//10x10
matrix = new IntegerMatrix(grid10);
assertTrue("IntegerMatrix = 10x10 failed equals IntegerMatrix", matrix.equals(matrix));
@SuppressWarnings("unlikely-arg-type")
boolean gridEquals10 = matrix.equals(grid10);
assertTrue("IntegerMatrix 10x10 failed equals int[][]", gridEquals10);
}
@Test
public void testGetsSetsAdds(){
//1x1
IntegerMatrix matrix = new IntegerMatrix(grid1);
assertEquals("IntegerMatrix 1x1 failed get", 1, matrix.get(0, 0));
//GetRow
IntegerMatrix correctMatrix = new IntegerMatrix(new int[][]{{1}});
assertEquals("IntegerMatrix 1x1 failed getRow", correctMatrix, matrix.getRow(0));
//GetColumn
correctMatrix = new IntegerMatrix(new int[][]{{1}});
assertEquals("IntegerMatrix 1x1 failed getColumn", correctMatrix, matrix.getCol(0));
//Set
matrix.set(0, 0, 2);
correctMatrix = new IntegerMatrix(new int[][]{{2}});
assertEquals("IntegerMatrix 1x1 failed set", correctMatrix, matrix);
//SetRow
matrix.setRow(0, new int[]{0});
correctMatrix = new IntegerMatrix(new int[][]{{0}});
assertEquals("IntegerMatrix 1x1 failed setRow", correctMatrix, matrix);
//SetColumn
matrix.setCol(0, new int[]{1});
correctMatrix = new IntegerMatrix(new int[][]{{1}});
assertEquals("IntegerMatrix 1x1 failed setCol", correctMatrix, matrix);
//AddRow
matrix.addRow(new int[]{1});
correctMatrix = new IntegerMatrix(new int[][]{{1}, {1}});
assertEquals("IntegerMatrix 1x1 failed addRow", correctMatrix, matrix);
//AddColumn
matrix = new IntegerMatrix(grid1);
matrix.addCol(new int[]{1});
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
//AddColumn
//3x3
matrix = new IntegerMatrix(grid3);
assertEquals("IntegerMatrix 3x3 failed get", 1, matrix.get(0, 0));
//GetRow
//GetColumn
//Set
//SetRow
//SetColumn
//AddRow
//AddColumn
//4x4
matrix = new IntegerMatrix(grid4);
assertEquals("IntegerMatrix 4x4 failed get", 1, matrix.get(0, 0));
//GetRow
//GetColumn
//Set
//SetRow
//SetColumn
//AddRow
//AddColumn
//10x10
matrix = new IntegerMatrix(grid10);
assertEquals("IntegerMatrix 10x10 failed get", 1, matrix.get(0, 0));
//GetRow
//GetColumn
//Set
//SetRow
//SetColumn
//AddRow
//AddColumn
}
@Test
public void testAddition(){
//1x1
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix transformMatrix = new IntegerMatrix(transformGrid1_1);
IntegerMatrix correctMatrix = new IntegerMatrix(new int[][]{{2}});
assertEquals("IntegerMatrix 1x1 failed add IntegerMatrix", correctMatrix, matrix.add(transformMatrix));
assertEquals("IntegerMatrix 1x1 failed add scalar", correctMatrix, matrix.add(1));
//2x2
matrix = new IntegerMatrix(grid2);
transformMatrix = new IntegerMatrix(transformGrid2_1);
correctMatrix = new IntegerMatrix(new int[][]{
{2, 2},
{2, 2}
});
assertEquals("IntegerMatrix 2x2 failed add IntegerMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 3},
{2, 3}
});
assertEquals("IntegerMatrix 2x2 failed add scalar", correctMatrix, matrix.add(1));
//3x3
matrix = new IntegerMatrix(grid3);
transformMatrix = new IntegerMatrix(transformGrid3_1);
correctMatrix = new IntegerMatrix(new int[][]{
{3, 3, 3},
{3, 3, 3},
{3, 3, 3}
});
assertEquals("IntegerMatrix 3x3 failed add IntegerMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 3, 4},
{2, 3, 4},
{2, 3, 4}
});
assertEquals("IntegerMatrix 3x3 failed add scalar", correctMatrix, matrix.add(1));
//4x4
matrix = new IntegerMatrix(grid4);
transformMatrix = new IntegerMatrix(transformGrid4_1);
correctMatrix = new IntegerMatrix(new int[][]{
{4, 4, 4, 4},
{4, 4, 4, 4},
{4, 4, 4, 4},
{4, 4, 4, 4}
});
assertEquals("IntegerMatrix 4x4 failed add IntegerMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 3, 4, 5},
{2, 3, 4, 5},
{2, 3, 4, 5},
{2, 3, 4, 5}
});
assertEquals("IntegerMatrix 4x4 failed add scalar", correctMatrix, matrix.add(1));
//10x10
matrix = new IntegerMatrix(grid10);
transformMatrix = new IntegerMatrix(transformGrid10_1);
correctMatrix = new IntegerMatrix(new int[][]{
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10}
});
assertEquals("IntegerMatrix 5x5 failed add IntegerMatrix", correctMatrix, matrix.add(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
});
assertEquals("IntegerMatrix 10x10 failed add IntegerMatrix", correctMatrix, matrix.add(1));
}
@Test
public void testSubtraction(){
//1x1
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix transformMatrix = new IntegerMatrix(transformGrid1_1);
IntegerMatrix correctMatrix = new IntegerMatrix(new int[][]{
{0}
});
assertEquals("IntegerMatrix 1x1 failed subtract IntegerMatrix", correctMatrix, matrix.subtract(transformMatrix));
assertEquals("IntegerMatrix 1x1 failed subtract scalar", correctMatrix, matrix.subtract(1));
//2x2
matrix = new IntegerMatrix(grid2);
transformMatrix = new IntegerMatrix(grid2);
correctMatrix = new IntegerMatrix(new int[][]{
{0, 0},
{0, 0}
});
assertEquals("IntegerMatrix 2x2 failed subtract IntegerMatrix", correctMatrix, matrix.subtract(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{0, 1},
{0, 1}
});
assertEquals("IntegerMatrix 2x2 failed subtract scalar", correctMatrix, matrix.subtract(1));
//3x3
matrix = new IntegerMatrix(grid3);
transformMatrix = new IntegerMatrix(grid3);
correctMatrix = new IntegerMatrix(new int[][]{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
});
assertEquals("IntegerMatrix 3x3 failed subtract IntegerMatrix", correctMatrix, matrix.subtract(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{0, 1, 2},
{0, 1, 2},
{0, 1, 2}
});
assertEquals("IntegerMatrix 3x3 failed subtract scalar", correctMatrix, matrix.subtract(1));
//4x4
matrix = new IntegerMatrix(grid4);
transformMatrix = new IntegerMatrix(grid4);
correctMatrix = new IntegerMatrix(new int[][]{
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}
});
assertEquals("IntegerMatrix 4x4 failed subtract IntegerMatrix", correctMatrix, matrix.subtract(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{0, 1, 2, 3},
{0, 1, 2, 3},
{0, 1, 2, 3},
{0, 1, 2, 3}
});
assertEquals("IntegerMatrix 4x4 failed subtract scalar", correctMatrix, matrix.subtract(1));
//10x10
matrix = new IntegerMatrix(grid10);
transformMatrix = new IntegerMatrix(grid10);
correctMatrix = new IntegerMatrix(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}
});
assertEquals("IntegerMatrix 10x10 failed subtract IntegerMatrix", correctMatrix, matrix.subtract(transformMatrix));
correctMatrix = new IntegerMatrix(new int[][]{
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
});
assertEquals("IntegerMatrix 10x10 failed subtract scalar", correctMatrix, matrix.subtract(1));
}
@Test
public void testMultiplication(){
//1x1
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix transformMatrix = new IntegerMatrix(transformGrid1_2);
IntegerMatrix correctMatrix = new IntegerMatrix(transformGrid1_2);
assertEquals("IntegerMatrix 1x1 failed multiplication IntegerMatrix", correctMatrix, matrix.multiply(transformMatrix));
assertEquals("IntegerMatrix 1x1 failed multiplication scalar", correctMatrix, matrix.multiply(2));
//2x2
matrix = new IntegerMatrix(grid2);
transformMatrix = new IntegerMatrix(transformGrid2_2);
correctMatrix = new IntegerMatrix(new int[][]{
{6, 9},
{6, 9}
});
assertEquals("IntegerMatrix 2x2 failed multiplication IntegerMatrix", correctMatrix, matrix.multiply(transformMatrix));
IntegerMatrix vector = new IntegerMatrix(new int[][]{
{2},
{3}
});
correctMatrix = new IntegerMatrix(new int[][]{
{8},
{8}
});
assertEquals("IntegerMatrix 2x2 failed multiplication vector", correctMatrix, matrix.multiply(vector));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 4},
{2, 4}
});
assertEquals("IntegerMatrix 2x2 failed multiplication scalar", correctMatrix, matrix.multiply(2));
//3x3
matrix = new IntegerMatrix(grid3);
transformMatrix = new IntegerMatrix(transformGrid3_2);
correctMatrix = new IntegerMatrix(new int[][]{
{12, 18, 24},
{12, 18, 24},
{12, 18, 24}
});
assertEquals("IntegerMatrix 3x3 failed multiplication IntegerMatrix", correctMatrix, matrix.multiply(transformMatrix));
vector = new IntegerMatrix(new int[][]{
{2},
{3},
{4}
});
correctMatrix = new IntegerMatrix(new int[][]{
{20},
{20},
{20}
});
assertEquals("IntegerMatrix 3x3 failed multiplication vector", correctMatrix, matrix.multiply(vector));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 4, 6},
{2, 4, 6},
{2, 4, 6}
});
assertEquals("IntegerMatrix 3x3 failed multiplication scalar", correctMatrix, matrix.multiply(2));
//4x4
matrix = new IntegerMatrix(grid4);
transformMatrix = new IntegerMatrix(transformGrid4_2);
correctMatrix = new IntegerMatrix(new int[][]{
{20, 30, 40, 50},
{20, 30, 40, 50},
{20, 30, 40, 50},
{20, 30, 40, 50},
});
assertEquals("IntegerMatrix 4x4 failed multiplication IntegerMatrix", correctMatrix, matrix.multiply(transformMatrix));
vector = new IntegerMatrix(new int[][]{
{2},
{3},
{4},
{5}
});
correctMatrix = new IntegerMatrix(new int[][]{
{40},
{40},
{40},
{40}
});
assertEquals("IntegerMatrix 4x4 failed multiplication vector", correctMatrix, matrix.multiply(vector));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 4, 6, 8},
{2, 4, 6, 8},
{2, 4, 6, 8},
{2, 4, 6, 8}
});
assertEquals("IntegerMatrix 4x4 failed multiplication scalar", correctMatrix, matrix.multiply(2));
//10x10
matrix = new IntegerMatrix(grid10);
transformMatrix = new IntegerMatrix(transformGrid10_2);
correctMatrix = new IntegerMatrix(new int[][]{
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605},
{110, 165, 220, 275, 330, 385, 440, 495, 550, 605}
});
assertEquals("IntegerMatrix 10x10 failed multiplication IntegerMatrix", correctMatrix, matrix.multiply(transformMatrix));
vector = new IntegerMatrix(new int[][]{
{2},
{3},
{4},
{5},
{6},
{7},
{8},
{9},
{10},
{11}
});
correctMatrix = new IntegerMatrix(new int[][]{
{440},
{440},
{440},
{440},
{440},
{440},
{440},
{440},
{440},
{440}
});
assertEquals("IntegerMatrix 10x10 failed multiplication vector", correctMatrix, matrix.multiply(vector));
correctMatrix = new IntegerMatrix(new int[][]{
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20},
{2, 4, 6, 8, 10, 12, 14, 16, 18, 20}
});
assertEquals("IntegerMatrix 10x10 failed multiplication scalar", correctMatrix, matrix.multiply(2));
}
@Test
public void testDotProduct(){
//1x1
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix transformMatrix = new IntegerMatrix(transformGrid1_2);
assertEquals("IntegerMatrix 1x1 failed dot product IntegerMatrix", 2, matrix.dotProduct(transformMatrix));
//2x2
matrix = new IntegerMatrix(grid2);
transformMatrix = new IntegerMatrix(transformGrid2_2);
assertEquals("IntegerMatrix 2x2 failed dot product IntegerMatrix", 30, matrix.dotProduct(transformMatrix));
//3x3
matrix = new IntegerMatrix(grid3);
transformMatrix = new IntegerMatrix(transformGrid3_2);
assertEquals("IntegerMatrix 3x3 failed dot product IntegerMatrix", 162, matrix.dotProduct(transformMatrix));
//4x4
matrix = new IntegerMatrix(grid4);
transformMatrix = new IntegerMatrix(transformGrid4_2);
assertEquals("IntegerMatrix 4x4 failed dot product IntegerMatrix", 560, matrix.dotProduct(transformMatrix));
//10x10
matrix = new IntegerMatrix(grid10);
transformMatrix = new IntegerMatrix(transformGrid10_2);
assertEquals("IntegerMatrix 10x10 failed dot product IntegerMatrix", 35750, matrix.dotProduct(transformMatrix));
}
@Test
public void testHadamardProduct(){
//1x1
IntegerMatrix matrix = new IntegerMatrix(grid1);
IntegerMatrix transformMatrix = new IntegerMatrix(transformGrid1_2);
IntegerMatrix correctMatrix = new IntegerMatrix(new int[][]{{2}});
assertEquals("IntegerMatrix 1x1 failed dot product IntegerMatrix", correctMatrix, matrix.hadamardProduct(transformMatrix));
//2x2
matrix = new IntegerMatrix(grid2);
transformMatrix = new IntegerMatrix(transformGrid2_2);
correctMatrix = new IntegerMatrix(new int[][]{
{2, 6},
{2, 6}
});
assertEquals("IntegerMatrix 2x2 failed dot product IntegerMatrix", correctMatrix, matrix.hadamardProduct(transformMatrix));
//3x3
matrix = new IntegerMatrix(grid3);
transformMatrix = new IntegerMatrix(transformGrid3_2);
correctMatrix = new IntegerMatrix(new int[][]{
{2, 6, 12},
{2, 6, 12},
{2, 6, 12}
});
assertEquals("IntegerMatrix 3x3 failed dot product IntegerMatrix", correctMatrix, matrix.hadamardProduct(transformMatrix));
//4x4
matrix = new IntegerMatrix(grid4);
transformMatrix = new IntegerMatrix(transformGrid4_2);
correctMatrix = new IntegerMatrix(new int[][]{
{2, 6, 12, 20},
{2, 6, 12, 20},
{2, 6, 12, 20},
{2, 6, 12, 20}
});
assertEquals("IntegerMatrix 4x4 failed dot product IntegerMatrix", correctMatrix, matrix.hadamardProduct(transformMatrix));
//10x10
matrix = new IntegerMatrix(grid10);
transformMatrix = new IntegerMatrix(transformGrid10_2);
correctMatrix = new IntegerMatrix(new int[][]{
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110},
{2, 6, 12, 20, 30, 42, 56, 72, 90, 110}
});
assertEquals("IntegerMatrix 10x10 failed dot product IntegerMatrix", correctMatrix, matrix.hadamardProduct(transformMatrix));
}
}