/**
* Test subtract exceptions.
*/
public void testSubtractExceptions() {
ComplexArray1D a = new ComplexArray1D(new Complex[] { new Complex(1, 1) });
// testing subtract(int, double, double, double, double)
try {
a.subtract(-1, 3d, 4d, 1d, 2d);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.subtract(5, 2d, 3d, 2d, 1d);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
// testing subtract(int, int, double, double)
try {
a.subtract(-1, 0, 1d, 1d);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.subtract(5, 0, 1d, 1d);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.subtract(0, -2, 1d, 1d);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.subtract(0, 10, 1d, 1d);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
// testing subtract(int, double, double, int)
try {
a.subtract(-1, 1d, 1d, 0);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.subtract(5, 1d, 1d, 0);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.subtract(0, 1d, 1d, -2);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.subtract(0, 1d, 1d, 10);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
// testing subtract(int, int, int)
try {
a.subtract(-1, 0, 0);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.add(5, 0, 0);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.add(0, -2, 0);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.add(0, 10, 0);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.add(0, 0, -1);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
try {
a.add(0, 0, 10);
fail();
} catch (IndexOutOfBoundsException e) {
assertTrue(true);
} catch (Exception e) {
fail();
}
// check for side-effects. Nothing should have changed!
assertTrue(a.getComplex(0).equals(new Complex(1, 1)));
}