mirror of
https://bitbucket.org/Mattrixwv/matrix.git
synced 2025-12-06 15:03:58 -05:00
Added adjoint and inverse functions
This commit is contained in:
@@ -1238,4 +1238,98 @@ public class TestIntegerMatrix{
|
||||
{2475, 4950, 7425, 9900, 12375, 14850, 17325, 19800, 22275, 24750}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdjoint(){
|
||||
//1x1
|
||||
IntegerMatrix matrix = new IntegerMatrix(grid1);
|
||||
IntegerMatrix correctMatrix = new IntegerMatrix(grid1);
|
||||
assertEquals("IntegerMatrix 1x1 failed adjoint", correctMatrix, matrix.adjoint());
|
||||
|
||||
//2x2
|
||||
matrix = new IntegerMatrix(grid2);
|
||||
correctMatrix = new IntegerMatrix(new int[][]{
|
||||
{2, -2},
|
||||
{-1, 1}
|
||||
});
|
||||
assertEquals("IntegerMatrix 2x2 failed adjoint", correctMatrix, matrix.adjoint());
|
||||
|
||||
//3x3
|
||||
matrix = new IntegerMatrix(grid3);
|
||||
correctMatrix = new IntegerMatrix(3, 3, 0);
|
||||
assertEquals("IntegerMatrix 3x3 failed adjoint", correctMatrix, matrix.adjoint());
|
||||
|
||||
//4x4
|
||||
matrix = new IntegerMatrix(new int[][]{
|
||||
{1, 2, 3, 4},
|
||||
{2, 3, 4, 1},
|
||||
{3, 4, 1, 2},
|
||||
{4, 1, 2, 3}
|
||||
});
|
||||
correctMatrix = new IntegerMatrix(new int[][]{
|
||||
{-36, 4, 4, 44},
|
||||
{4, 4, 44, -36},
|
||||
{4, 44, -36, 4},
|
||||
{44, -36, 4, 4}
|
||||
});
|
||||
assertEquals("IntegerMatrix 4x4 failed adjoint", correctMatrix, matrix.adjoint());
|
||||
|
||||
//10x10
|
||||
//?Skipping 10x10 test because test took > 5s by itself
|
||||
/*
|
||||
matrix = new IntegerMatrix(grid10);
|
||||
correctMatrix = new IntegerMatrix(10, 10, 0);
|
||||
assertEquals("IntegerMatrix 10x10 failed adjoint", correctMatrix, matrix.adjoint());
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInverse(){
|
||||
//1x1
|
||||
IntegerMatrix matrix = new IntegerMatrix(grid1);
|
||||
IntegerMatrix correctMatrix = new IntegerMatrix(grid1);
|
||||
assertEquals("IntegerMatrix 1x1 failed inverse", correctMatrix, matrix.inverse());
|
||||
|
||||
//2x2
|
||||
matrix = new IntegerMatrix(new int[][]{
|
||||
{1, 4},
|
||||
{4, 1}
|
||||
});
|
||||
correctMatrix = new IntegerMatrix(new int[][]{
|
||||
{-0, 0},
|
||||
{0, -0}
|
||||
});
|
||||
assertEquals("IntegerMatrix 2x2 failed inverse", correctMatrix, matrix.inverse());
|
||||
|
||||
//3x3
|
||||
matrix = new IntegerMatrix(new int[][]{
|
||||
{1, 4, 2},
|
||||
{2, 4, 1},
|
||||
{4, 1, 2}
|
||||
});
|
||||
correctMatrix = new IntegerMatrix(new int[][]{
|
||||
{-0, 0, 0},
|
||||
{0, 0, -0},
|
||||
{0, -0, 0}
|
||||
});
|
||||
assertEquals("IntegerMatrix 3x3 failed inverse", correctMatrix, matrix.inverse());
|
||||
|
||||
//4x4
|
||||
matrix = new IntegerMatrix(new int[][]{
|
||||
{1, 2, 3, 4},
|
||||
{2, 3, 4, 1},
|
||||
{3, 4, 1, 2},
|
||||
{4, 1, 2, 3}
|
||||
});
|
||||
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 inverse", correctMatrix, matrix.inverse());
|
||||
|
||||
//10x10
|
||||
//?Skipped 10x10 because it would take a long time to compute
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user