public void testSeveralBlocks() {
FieldMatrix<Fraction> m =
new BlockFieldMatrix<Fraction>(FractionField.getInstance(), 37, 41);
for (int i = 0; i < m.getRowDimension(); ++i) {
for (int j = 0; j < m.getColumnDimension(); ++j) {
m.setEntry(i, j, new Fraction(i * 11 + j, 11));
}
}
FieldMatrix<Fraction> mT = m.transpose();
Assert.assertEquals(m.getRowDimension(), mT.getColumnDimension());
Assert.assertEquals(m.getColumnDimension(), mT.getRowDimension());
for (int i = 0; i < mT.getRowDimension(); ++i) {
for (int j = 0; j < mT.getColumnDimension(); ++j) {
Assert.assertEquals(m.getEntry(j, i), mT.getEntry(i, j));
}
}
FieldMatrix<Fraction> mPm = m.add(m);
for (int i = 0; i < mPm.getRowDimension(); ++i) {
for (int j = 0; j < mPm.getColumnDimension(); ++j) {
Assert.assertEquals(m.getEntry(i, j).multiply(new Fraction(2)), mPm.getEntry(i, j));
}
}
FieldMatrix<Fraction> mPmMm = mPm.subtract(m);
for (int i = 0; i < mPmMm.getRowDimension(); ++i) {
for (int j = 0; j < mPmMm.getColumnDimension(); ++j) {
Assert.assertEquals(m.getEntry(i, j), mPmMm.getEntry(i, j));
}
}
FieldMatrix<Fraction> mTm = mT.multiply(m);
for (int i = 0; i < mTm.getRowDimension(); ++i) {
for (int j = 0; j < mTm.getColumnDimension(); ++j) {
Fraction sum = Fraction.ZERO;
for (int k = 0; k < mT.getColumnDimension(); ++k) {
sum = sum.add(new Fraction(k * 11 + i, 11).multiply(new Fraction(k * 11 + j, 11)));
}
Assert.assertEquals(sum, mTm.getEntry(i, j));
}
}
FieldMatrix<Fraction> mmT = m.multiply(mT);
for (int i = 0; i < mmT.getRowDimension(); ++i) {
for (int j = 0; j < mmT.getColumnDimension(); ++j) {
Fraction sum = Fraction.ZERO;
for (int k = 0; k < m.getColumnDimension(); ++k) {
sum = sum.add(new Fraction(i * 11 + k, 11).multiply(new Fraction(j * 11 + k, 11)));
}
Assert.assertEquals(sum, mmT.getEntry(i, j));
}
}
FieldMatrix<Fraction> sub1 = m.getSubMatrix(2, 9, 5, 20);
for (int i = 0; i < sub1.getRowDimension(); ++i) {
for (int j = 0; j < sub1.getColumnDimension(); ++j) {
Assert.assertEquals(new Fraction((i + 2) * 11 + (j + 5), 11), sub1.getEntry(i, j));
}
}
FieldMatrix<Fraction> sub2 = m.getSubMatrix(10, 12, 3, 40);
for (int i = 0; i < sub2.getRowDimension(); ++i) {
for (int j = 0; j < sub2.getColumnDimension(); ++j) {
Assert.assertEquals(new Fraction((i + 10) * 11 + (j + 3), 11), sub2.getEntry(i, j));
}
}
FieldMatrix<Fraction> sub3 = m.getSubMatrix(30, 34, 0, 5);
for (int i = 0; i < sub3.getRowDimension(); ++i) {
for (int j = 0; j < sub3.getColumnDimension(); ++j) {
Assert.assertEquals(new Fraction((i + 30) * 11 + (j + 0), 11), sub3.getEntry(i, j));
}
}
FieldMatrix<Fraction> sub4 = m.getSubMatrix(30, 32, 32, 35);
for (int i = 0; i < sub4.getRowDimension(); ++i) {
for (int j = 0; j < sub4.getColumnDimension(); ++j) {
Assert.assertEquals(new Fraction((i + 30) * 11 + (j + 32), 11), sub4.getEntry(i, j));
}
}
}