@Override @Test public void listIterator() { super.listIterator(); CompositeFastList<String> composite = new CompositeFastList<String>(); FastList<String> firstBit = FastList.newListWith("one", "two"); FastList<String> secondBit = FastList.newListWith("three"); composite.addAll(firstBit); composite.addAll(secondBit); ListIterator<String> listIterator = composite.listIterator(); listIterator.add("four"); Verify.assertSize(4, composite); Assert.assertTrue(listIterator.hasNext()); String element = listIterator.next(); Assert.assertEquals("one", element); String element3 = listIterator.next(); Assert.assertEquals("two", element3); String element2 = listIterator.previous(); Assert.assertEquals("two", element2); String element1 = listIterator.next(); Assert.assertEquals("two", element1); listIterator.remove(); Verify.assertSize(3, composite); }
@Override protected <T> MutableList<T> newWith(T... littleElements) { CompositeFastList<T> result = new CompositeFastList<T>(); for (T element : littleElements) { result.add(element); } return result; }
@Override @Test public void reverseThis() { super.reverseThis(); CompositeFastList<Integer> composite = new CompositeFastList<Integer>(); composite.addAll(FastList.newListWith(9, 8, 7)); composite.addAll(FastList.newListWith(6, 5, 4)); composite.addAll(FastList.newListWith(3, 2, 1)); CompositeFastList<Integer> reversed = composite.reverseThis(); Assert.assertSame(composite, reversed); Assert.assertEquals(Interval.oneTo(9), reversed); }
@Override @Test public void forEach() { super.forEach(); MutableList<Integer> list = FastList.newList(); CompositeFastList<Integer> iterables = new CompositeFastList<Integer>(); iterables.addComposited(Interval.oneTo(5).toList()); iterables.addComposited(Interval.fromTo(6, 10).toList()); iterables.forEach(CollectionAddProcedure.on(list)); Verify.assertSize(10, list); Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11))); }
@Override @Test public void forEachWith() { super.forEachWith(); MutableList<Integer> list = FastList.newList(); CompositeFastList<Integer> iterables = new CompositeFastList<Integer>(); iterables.addComposited(Interval.fromTo(6, 10).toList()); iterables.addComposited(Interval.oneTo(5).toList()); iterables.forEachWith((each, parameter) -> list.add(parameter.intValue(), each), 0); Verify.assertSize(10, list); Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11))); Verify.assertStartsWith(list, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6); }
@Override @Test public void forEachWithIndex() { super.forEachWithIndex(); MutableList<Integer> list = FastList.newList(); CompositeFastList<Integer> iterables = new CompositeFastList<Integer>(); iterables.addComposited(Interval.fromTo(6, 10).toList()); iterables.addComposited(Interval.oneTo(5).toList()); iterables.forEachWithIndex((each, index) -> list.add(index, each)); Verify.assertSize(10, list); Verify.assertAllSatisfy(list, Predicates.greaterThan(0).and(Predicates.lessThan(11))); Verify.assertStartsWith(list, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5); }
@Test public void removingFromIteratorIsCool() { CompositeFastList<String> undertest = new CompositeFastList<String>(); undertest.addAll(FastList.newListWith("a")); undertest.addAll(FastList.newListWith("b", "c", "d")); Iterator<String> iterator1 = undertest.iterator(); iterator1.next(); iterator1.next(); iterator1.next(); iterator1.remove(); Assert.assertEquals("d", iterator1.next()); Assert.assertEquals(FastList.newListWith("a", "b", "d"), undertest); Iterator<String> iterator2 = undertest.iterator(); iterator2.next(); iterator2.next(); iterator2.remove(); Assert.assertEquals(FastList.newListWith("a", "d"), undertest); Iterator<String> iterator3 = undertest.iterator(); iterator3.next(); iterator3.remove(); Assert.assertEquals(FastList.newListWith("d"), undertest); iterator3.next(); iterator3.remove(); Assert.assertEquals(FastList.newList(), undertest); }
@Test public void testHashCode() { CompositeFastList<String> composite = new CompositeFastList<String>(); MutableList<String> list = FastList.newList(); Verify.assertEqualsAndHashCode(composite, list); MutableList<String> list2 = FastList.newListWith("one", "two", "three"); CompositeFastList<String> composite2 = new CompositeFastList<String>(); MutableList<String> firstBit = FastList.newListWith("one", "two"); MutableList<String> secondBit = FastList.newListWith("three"); composite2.addAll(firstBit); composite2.addAll(secondBit); Verify.assertEqualsAndHashCode(list2, composite2); MutableList<String> list1 = FastList.newListWith("one", null, "three"); CompositeFastList<String> composite1 = new CompositeFastList<String>(); MutableList<String> firstBit1 = FastList.newListWith("one", null); MutableList<String> secondBit1 = FastList.newListWith("three"); composite1.addAll(firstBit1); composite1.addAll(secondBit1); Verify.assertEqualsAndHashCode(list1, composite1); }
@Test public void set_bugFix_off_by_one_error() { CompositeFastList<Integer> compositeList = new CompositeFastList<Integer>(); MutableList<Integer> list1 = FastList.newListWith(1, 2, 3); MutableList<Integer> list2 = FastList.newListWith(4, 5); MutableList<Integer> list3 = FastList.newList(); compositeList.addAll(list1); compositeList.addAll(list2); compositeList.addAll(list3); Assert.assertEquals(Integer.valueOf(4), compositeList.get(3)); Assert.assertEquals(Integer.valueOf(4), compositeList.set(3, 99)); Assert.assertEquals(Integer.valueOf(99), compositeList.get(3)); }