/**
* Tests {@link ArrayOfInt}.
*/
public void testArraysOfInts() {
// This is our test subject.
final ArrayOfInt array = Collections.arrayOfInt();
// These are items to put in him.
final int[] items = new int[] {0, 1, 2};
// Let's put the items in him.
for (int i = 0, n = items.length; i < n; ++i) {
array.push(items[i]);
}
// Are the items in the right places?
assertEquals(items.length, array.length());
for (int i = 0, n = items.length; i < n; ++i) {
assertEquals(items[i], array.get(i));
}
// These are some more items to put in him.
final int[] newItems = new int[] {3, 4, 5};
// Put all these items in where the others were.
for (int i = 0, n = items.length; i < n; ++i) {
array.set(i, newItems[i]);
assertEquals(newItems[i], array.get(i));
}
// Shift our test subject to squeeze out the first item.
assertEquals(newItems[0], array.shift());
assertEquals(newItems.length - 1, array.length());
// Then Unshift.
array.unshift(newItems[0]);
assertEquals(newItems[0], array.get(0));
assertEquals(newItems.length, array.length());
// Now join them together in harmony.
assertEquals("3$4$5", array.join("$"));
for (int i = 0, n = items.length; i < n; ++i) {
assertEquals(i, array.indexOf(newItems[i]));
assertTrue(array.contains(newItems[i]));
}
final int imposter = 100;
assertEquals(-1, array.indexOf(imposter));
assertFalse(array.contains(imposter));
final int[] itemsA = new int[] {11, 12};
final int[] itemsB = new int[] {13, 14};
final ArrayOfInt a = arrayFrom(itemsA);
final ArrayOfInt b = arrayFrom(itemsB);
assertSamelitude(new int[] {itemsA[0], itemsA[1], itemsB[0], itemsB[1]}, a.concat(b));
assertSamelitude(itemsA, a);
assertSamelitude(itemsB, b);
}