private void testGetElem2(TestHarness harness) {
harness.checkPoint("getElem(int, int)");
double[][] source = new double[][] {{1, 2}, {3, 4}};
DataBufferDouble b = new DataBufferDouble(source, 2);
harness.check(b.getElem(1, 0) == 3);
harness.check(b.getElem(1, 1) == 4);
// test where supplied array is bigger than 'size'
source = new double[][] {{1, 2, 3}, {4, 5, 6}};
b = new DataBufferDouble(source, 2);
harness.check(b.getElem(1, 2) == 6);
// test where offsets are specified
source = new double[][] {{1, 2, 3, 4}, {5, 6, 7, 8}};
b = new DataBufferDouble(source, 2, new int[] {1, 2});
harness.check(b.getElem(1, -2) == 5);
harness.check(b.getElem(1, -1) == 6);
harness.check(b.getElem(1, 0) == 7);
harness.check(b.getElem(1, 1) == 8);
// does a change to the source affect the DataBuffer? Yes
source[1][2] = 99;
harness.check(source[1][2] == 99);
harness.check(b.getElem(1, 0) == 99);
// test when the bank index is out of bounds
boolean pass = true;
try
{
b.getElem(-1, 0);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
b.getElem(2, 0);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// test when the item index is out of bounds
pass = true;
try
{
b.getElem(0, -2);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
b.getElem(1, 5);
}
catch (ArrayIndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// the array of arrays should reflect the single dimension array
DataBufferDouble b2 = new DataBufferDouble(new double[] {1, 2, 3}, 3);
harness.check(b2.getElem(0, 1) == 2);
}