/**
* Tests {@link ArrayOfNumber}.
*/
public void testArraysOfNumbers() {
// This is our test subject.
final ArrayOfNumber array = Collections.arrayOfNumber();
// These are items to put in him.
final double[] items = new double[] {0.0, 1.0, 2.0};
// 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 double[] newItems = new double[] {3.0, 4.0, 5.0};
// 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("$"));
final double[] itemsA = new double[] {0.01, 0.02};
final double[] itemsB = new double[] {0.03, 0.04};
final ArrayOfNumber a = arrayFrom(itemsA);
final ArrayOfNumber b = arrayFrom(itemsB);
assertSamelitude(new double[] {itemsA[0], itemsA[1], itemsB[0], itemsB[1]}, a.concat(b));
assertSamelitude(itemsA, a);
assertSamelitude(itemsB, b);
}