static List populatedArray(int n) { List a = ParallelArray.createEmpty(n, Object.class, ParallelArray.defaultExecutor()).asList(); assertTrue(a.isEmpty()); for (int i = 0; i < n; ++i) a.add(new Integer(i)); assertFalse(a.isEmpty()); assertEquals(n, a.size()); return a; }
/** adding at an index places it in the indicated index */ public void testAddIndex() { List full = populatedArray(3); full.add(0, m1); assertEquals(4, full.size()); assertEquals(m1, full.get(0)); assertEquals(zero, full.get(1)); full.add(2, m2); assertEquals(5, full.size()); assertEquals(m2, full.get(2)); assertEquals(two, full.get(4)); }
/** removeAll removes all elements from the given collection */ public void testRemoveAll() { List full = populatedArray(3); Vector v = new Vector(); v.add(one); v.add(two); full.removeAll(v); assertEquals(1, full.size()); }
/** addAll adds each element from the given collection */ public void testAddAll() { List full = populatedArray(3); Vector v = new Vector(); v.add(three); v.add(four); v.add(five); full.addAll(v); assertEquals(6, full.size()); }
/** sublists contains elements at indexes offset from their base */ public void testSubList() { List a = populatedArray(10); assertTrue(a.subList(1, 1).isEmpty()); for (int j = 0; j < 9; ++j) { for (int i = j; i < 10; ++i) { List b = a.subList(j, i); for (int k = j; k < i; ++k) { assertEquals(new Integer(k), b.get(k - j)); } } } List s = a.subList(2, 5); assertEquals(3, s.size()); s.set(2, m1); assertEquals(a.get(4), m1); s.clear(); assertEquals(7, a.size()); }
/** clear removes all elements from the list */ public void testClear() { List full = populatedArray(SIZE); full.clear(); assertEquals(0, full.size()); }
/** size returns the number of elements */ public void testSize() { List empty = emptyArray(); List full = populatedArray(SIZE); assertEquals(SIZE, full.size()); assertEquals(0, empty.size()); }
/** remove removes and returns the object at the given index */ public void testRemove() { List full = populatedArray(3); assertEquals(two, full.remove(2)); assertEquals(2, full.size()); }