@Test
public void testSet() {
int[] original = new int[] { 2,4,6,8,10,12,14 };
int[] toSet = new int[] { 1,3,5,7,9,11};
IntArray arr = new IntArray();
for (int val : original) {
arr.addToArray(val);
}
for (int i = 0; i < toSet.length; i++ ) {
int val = toSet[i];
arr.set(i, val);
}
// Test to see if the set worked correctly
for (int i = 0; i < toSet.length; i++ ) {
assertEquals(toSet[i], arr.get(i));
}
// Now attempt to set something outside of the array
try {
arr.set(100, 99);
fail("IntArray.set should have thrown an exception for attempting to set outside the array");
} catch (ArrayIndexOutOfBoundsException e) {
// We expected this to happen so let it fall through
// silently
}