Added power function
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//Matrix/src/test/java/com/mattrixwv/matrix/TestIntegerMatrix.java
|
//Matrix/src/test/java/com/mattrixwv/matrix/TestIntegerMatrix.java
|
||||||
//Mattrixwv
|
//Mattrixwv
|
||||||
// Created: 02-01-22
|
// Created: 02-01-22
|
||||||
//Modified: 02-03-22
|
//Modified: 02-07-22
|
||||||
package com.mattrixwv.matrix;
|
package com.mattrixwv.matrix;
|
||||||
|
|
||||||
|
|
||||||
@@ -1171,4 +1171,71 @@ public class TestIntegerMatrix{
|
|||||||
assertEquals("IntegerMatrix 10x10 failed cofactor1", correctMatrix, matrix.cofactor());
|
assertEquals("IntegerMatrix 10x10 failed cofactor1", correctMatrix, matrix.cofactor());
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPower(){
|
||||||
|
//1x1
|
||||||
|
IntegerMatrix matrix = new IntegerMatrix(grid1);
|
||||||
|
IntegerMatrix correctMatrix = new IntegerMatrix(new int[][]{{1}});
|
||||||
|
assertEquals("IntegerMatrix 1x1 failed power", correctMatrix, matrix.pow(3));
|
||||||
|
|
||||||
|
//2x2
|
||||||
|
matrix = new IntegerMatrix(grid2);
|
||||||
|
correctMatrix = new IntegerMatrix(new int[][]{
|
||||||
|
{9, 18},
|
||||||
|
{9, 18}
|
||||||
|
});
|
||||||
|
assertEquals("IntegerMatrix 2x2 failed power", correctMatrix, matrix.pow(3));
|
||||||
|
|
||||||
|
//3x3
|
||||||
|
matrix = new IntegerMatrix(grid3);
|
||||||
|
correctMatrix = new IntegerMatrix(new int[][]{
|
||||||
|
{36, 72, 108},
|
||||||
|
{36, 72, 108},
|
||||||
|
{36, 72, 108}
|
||||||
|
});
|
||||||
|
assertEquals("IntegerMatrix 3x3 failed power", correctMatrix, matrix.pow(3));
|
||||||
|
|
||||||
|
//4x4
|
||||||
|
//0
|
||||||
|
matrix = new IntegerMatrix(grid4);
|
||||||
|
correctMatrix = new IntegerMatrix(new int[][]{
|
||||||
|
{1, 1, 1, 1},
|
||||||
|
{1, 1, 1, 1},
|
||||||
|
{1, 1, 1, 1},
|
||||||
|
{1, 1, 1, 1}
|
||||||
|
});
|
||||||
|
assertEquals("IntegerMatrix 4x4 failed power 0", correctMatrix, matrix.pow(0));
|
||||||
|
//1
|
||||||
|
correctMatrix = new IntegerMatrix(new int[][]{
|
||||||
|
{1, 2, 3, 4},
|
||||||
|
{1, 2, 3, 4},
|
||||||
|
{1, 2, 3, 4},
|
||||||
|
{1, 2, 3, 4}
|
||||||
|
});
|
||||||
|
assertEquals("IntegerMatrix 4x4 failed power 1", correctMatrix, matrix.pow(1));
|
||||||
|
//3
|
||||||
|
correctMatrix = new IntegerMatrix(new int[][]{
|
||||||
|
{100, 200, 300, 400},
|
||||||
|
{100, 200, 300, 400},
|
||||||
|
{100, 200, 300, 400},
|
||||||
|
{100, 200, 300, 400}
|
||||||
|
});
|
||||||
|
assertEquals("IntegerMatrix 4x4 failed power 3", correctMatrix, matrix.pow(3));
|
||||||
|
|
||||||
|
//10x10
|
||||||
|
matrix = new IntegerMatrix(grid10);
|
||||||
|
correctMatrix = new IntegerMatrix(new int[][]{
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750},
|
||||||
|
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user