assertEquals(expectedRow[i], a.get(0, i));
}
}
public void testAddRow() {
JavaArray2D a = new JavaArray2D();
double[] row0 = new double[] {1, 2};
double[] row1 = new double[] {3, 4};
a.addRowByRef(row0);
a.addRowByValue(row1);
assertEquals(1.0, a.get(0, 0));
assertEquals(2.0, a.get(0, 1));
assertEquals(3.0, a.get(1, 0));
assertEquals(4.0, a.get(1, 1));
// Row0 was added by reference. Verify that JavaArray2D actually points to row0
row0[0] = 999.0;
assertEquals(999.0, a.get(0, 0));
// row1 was added by value. Verify that JavaArray2D is not affected by changes
// to row1's state.
row1[0] = 999.0;
assertEquals(3.0, a.get(1, 0));
// Verify that access to the array elemts via the Array1D interface
// works as expected
for (int i = 0; i < a.numRows(); i++) {
for (int j = 0; j < a.numColumns(i); j++) {
assertEquals(a.get(i, j), a.getRow(i).get(j));
}
}
}