@Test
public void testSetSubMatrix() {
SparseFieldMatrix<Fraction> m = createSparseMatrix(testData);
m.setSubMatrix(detData2, 1, 1);
FieldMatrix<Fraction> expected = createSparseMatrix(new Fraction[][] {
{ new Fraction(1), new Fraction(2), new Fraction(3) }, { new Fraction(2), new Fraction(1), new Fraction(3) }, { new Fraction(1), new Fraction(2), new Fraction(4) } });
Assert.assertEquals(expected, m);
m.setSubMatrix(detData2, 0, 0);
expected = createSparseMatrix(new Fraction[][] {
{ new Fraction(1), new Fraction(3), new Fraction(3) }, { new Fraction(2), new Fraction(4), new Fraction(3) }, { new Fraction(1), new Fraction(2), new Fraction(4) } });
Assert.assertEquals(expected, m);
m.setSubMatrix(testDataPlus2, 0, 0);
expected = createSparseMatrix(new Fraction[][] {
{ new Fraction(3), new Fraction(4), new Fraction(5) }, { new Fraction(4), new Fraction(7), new Fraction(5) }, { new Fraction(3), new Fraction(2), new Fraction(10) } });
Assert.assertEquals(expected, m);
// javadoc example
SparseFieldMatrix<Fraction> matrix =
createSparseMatrix(new Fraction[][] {
{ new Fraction(1), new Fraction(2), new Fraction(3), new Fraction(4) }, { new Fraction(5), new Fraction(6), new Fraction(7), new Fraction(8) }, { new Fraction(9), new Fraction(0), new Fraction(1), new Fraction(2) } });
matrix.setSubMatrix(new Fraction[][] { { new Fraction(3), new Fraction(4) }, { new Fraction(5), new Fraction(6) } }, 1, 1);
expected = createSparseMatrix(new Fraction[][] {
{ new Fraction(1), new Fraction(2), new Fraction(3), new Fraction(4) }, { new Fraction(5), new Fraction(3), new Fraction(4), new Fraction(8) }, { new Fraction(9), new Fraction(5), new Fraction(6), new Fraction(2) } });
Assert.assertEquals(expected, matrix);
// dimension overflow
try {
m.setSubMatrix(testData, 1, 1);
Assert.fail("expecting OutOfRangeException");
} catch (OutOfRangeException e) {
// expected
}
// dimension underflow
try {
m.setSubMatrix(testData, -1, 1);
Assert.fail("expecting OutOfRangeException");
} catch (OutOfRangeException e) {
// expected
}
try {
m.setSubMatrix(testData, 1, -1);
Assert.fail("expecting OutOfRangeException");
} catch (OutOfRangeException e) {
// expected
}
// null
try {
m.setSubMatrix(null, 1, 1);
Assert.fail("expecting NullArgumentException");
} catch (NullArgumentException e) {
// expected
}
try {
new SparseFieldMatrix<Fraction>(field, 0, 0);
Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException e) {
// expected
}
// ragged
try {
m.setSubMatrix(new Fraction[][] { { new Fraction(1) }, { new Fraction(2), new Fraction(3) } }, 0, 0);
Assert.fail("expecting MathIllegalArgumentException");
} catch (MathIllegalArgumentException e) {
// expected
}