public void testInsertMultiple() { for (WritableLongList list: empty()) { list.insertMultiple(0, 0, 10); checkCollection(list, ap(0, 10, 0)); list.insertMultiple(0, 0, 10); checkCollection(list, ap(0, 20, 0)); list.insertMultiple(0, 1, 10); checkCollectionM(list, ap(1, 10, 0), ap(0, 20, 0)); list.insertMultiple(5, 2, 4); checkCollectionM(list, ap(1, 5, 0), ap(2, 4, 0), ap(1, 5, 0), ap(0, 20, 0)); list.insertMultiple(34, 0, 4); checkCollectionM(list, ap(1, 5, 0), ap(2, 4, 0), ap(1, 5, 0), ap(0, 24, 0)); list.insertMultiple(38, 100, 4); checkCollectionM(list, ap(1, 5, 0), ap(2, 4, 0), ap(1, 5, 0), ap(0, 24, 0), ap(100, 4, 0)); list.insertMultiple(5, 1, 1); checkCollectionM(list, ap(1, 6, 0), ap(2, 4, 0), ap(1, 5, 0), ap(0, 24, 0), ap(100, 4, 0)); list.insertMultiple(6, 2, 1); checkCollectionM(list, ap(1, 6, 0), ap(2, 5, 0), ap(1, 5, 0), ap(0, 24, 0), ap(100, 4, 0)); list.insertMultiple(6, 3, 1); checkCollectionM(list, ap(1, 6, 0), ap(3, 1, 0), ap(2, 5, 0), ap(1, 5, 0), ap(0, 24, 0), ap(100, 4, 0)); } }
public void testCopySubList() { for (WritableLongList list: empty()) { for (int i = 0; i < 10240; i++) { list.add(i); } list.addAll(list); checkList(list, ap(0, 10240, 1), ap(0, 10240, 1)); list.setAll(100, list, 100, 100); checkList(list, ap(0, 10240, 1), ap(0, 10240, 1)); list.setAll(100, list.subList(200, 300)); checkList(list, ap(0, 100, 1), ap(200, 100, 1), ap(200, 10040, 1), ap(0, 10240, 1)); list.insertAll(5000, list.subList(3000, 5000)); checkList(list, ap(0, 100, 1), ap(200, 100, 1), ap(200, 4800, 1), ap(3000, 2000, 1), ap(5000, 5240, 1), ap(0, 10240, 1)); } }
public void testCopyInsertList() { for (WritableLongList list: empty()) { list.addAll(LongProgression.arithmetic(0, 10240, 1)); LongArray src = new LongArray(); src.addAll(list); list.insertAll(2000, src, 100, 10000); checkList(list, ap(0, 2000, 1), ap(100, 10000, 1), ap(2000, 8240, 1)); list.setAll(5000, src); checkList(list, ap(0, 2000, 1), ap(100, 3000, 1), ap(0, 10240, 1), ap(5240, 5000, 1)); } }
public void testApply() { for (WritableLongList list: createWritableLongLists(ap(0, 10, 1))) { long[] expected = ap(0, 10, 1); list.apply(2, 8, new LongToLong() { @Override public long invoke(long a) { return a * a - 1; } }); for (int i = 2; i < 8; i++) { expected[i] = expected[i] * expected[i] - 1; } checkList(list, expected); } }
public void testInserts() { for (WritableLongList list: empty()) { list.insertMultiple(0, 1, 2048); checkList(list, ap(1, 2048, 0)); list.insert(0, 2); list.insert(list.size(), 3); checkList(list, new long[] {2}, ap(1, 2048, 0), new long[] {3}); list.insertMultiple(1, 2, 2000); checkList(list, ap(2, 2001, 0), ap(1, 2048, 0), new long[]{3}); list.clear(); // test shifts reusing whole segments list.insertMultiple(0, 1, 1024); list.insertMultiple(0, 2, 1024); checkList(list, ap(2, 1024, 0), ap(1, 1024, 0)); list.insertMultiple(1024, 3, 1024); checkList(list, ap(2, 1024, 0), ap(3, 1024, 0), ap(1, 1024, 0)); list.insertMultiple(1024, 4, 1024); checkList(list, ap(2, 1024, 0), ap(4, 1024, 0), ap(3, 1024, 0), ap(1, 1024, 0)); list.clear(); list.insertMultiple(0, 1, 10240); checkList(list, ap(1, 10240, 0)); list.insertMultiple(6000, 2, 1024); checkList(list, ap(1, 6000, 0), ap(2, 1024, 0), ap(1, 1024 * 11 - 7024, 0)); list.insertMultiple(2000, 3, 1024); checkList(list, ap(1, 2000, 0), ap(3, 1024, 0), ap(1, 7024 - 3024, 0), ap(2, 1024, 0), ap(1, 1024 * 12 - 8048, 0)); } }
public void testRemoves() { for (WritableLongList list: empty()) { for (int i = 0; i < 10000; i++) list.add(i); list.removeRange(0, 1024); list.removeRange(10000 - 2048, 10000 - 1024); list.removeRange(0, 10); checkList(list, ap(1034, 7942, 1)); list.removeAt(5000); checkList(list, ap(1034, 5000, 1), ap(6035, 2941, 1)); } }
public void testSetRange() { for (WritableLongList list: createWritableLongLists(ap(0, 20, 1))) { long[] expected = ap(0, 20, 1); list.setRange(0, 5, -1); for (int i = 0; i < 5; i++) { expected[i] = -1; } checkList(list, expected); list.setRange(5, 10, 4); for (int i = 5; i < 10; i++) { expected[i] = 4; } checkList(list, expected); } }
public void testIteratorRemoveFromEnd() { for (WritableLongList list: empty()) { for (int i = 0; i < 10000; i++) list.add(i); WritableLongListIterator ii = list.iterator(8191, 9192); ii.nextValue(); while (ii.hasNext()) { ii.nextValue(); ii.remove(); checkJustRemoved(ii); } checkList(list, ap(0, 8192, 1), ap(9192, 808, 1)); } }
public void testIteratorRemoveRange() { for (WritableLongList list: empty()) { for (int i = 0; i < 10000; i++) list.add(i); WritableLongListIterator ii = list.iterator(100, 600); for (int i = 0; i < 10; i++) ii.nextValue(); ii.removeRange(-9, 1); checkJustRemoved(ii); try { ii.removeRange(-9, 1); fail(); } catch (IllegalStateException e) {} ii.next(); ii.move(19); ii.removeRange(-9, 1); checkJustRemoved(ii); checkList(list, ap(0, 100, 1), ap(110, 10, 1), ap(130, 9870, 1)); ii.next(); ii.removeRange(-10, 0); checkJustRemoved(ii); checkList(list, ap(0, 100, 1), ap(130, 9870, 1)); } }
public void testInsertException() { for (WritableLongList list: createWritableLongLists(ap(0, 10, 1))) { try { list.insert(-1, 10); fail(); } catch (IndexOutOfBoundsException ex) {} try { list.insert(15, 10); fail(); } catch (IndexOutOfBoundsException ex) {} } }
public void testSubList() { for (WritableLongList list: empty()) { list.addAll(range(0, 10000)); checkList(list.subList(10, 20), ap(10, 10, 1)); checkList(list.subList(10, 10000), ap(10, 9990, 1)); checkList(list.subList(9990, 10000), ap(9990, 10, 1)); checkList(list.subList(9990, 9990)); assertEquals(list, list.subList(0, 10000)); assertTrue(list == list.subList(0, 10000)); } }
public void testIteratorRemove2() { for (WritableLongList list: createWritableLongLists(ap(0, 10, 1))) { WritableLongListIterator it = list.iterator(); it.next().next().next().next(); assertEquals(3, it.value()); it.remove(); checkJustRemoved(it); assertEquals(4, it.nextValue()); } }
public void testRemove() { for (WritableLongList list: createWritableLongLists(ap(1, 10, 1))) { checkCollection(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); list.remove(5); checkCollection(list, 1, 2, 3, 4, 6, 7, 8, 9, 10); list.removeRange(6, 8); checkCollection(list, 1, 2, 3, 4, 6, 7, 10); list.removeRange(5, 7); checkCollection(list, 1, 2, 3, 4, 6); list.removeRange(0, 3); checkCollection(list, 4, 6); list.removeRange(0, 2); checkCollection(list); } }
public void testAdd() { for (WritableLongList list: empty()) { for (int j = 0; j < 2; j++) { list.addAll(0, 1, 2); checkCollection(list, 0, 1, 2); list.addAll(LongArray.create(3, 4, 5, 6)); checkCollection(list, 0, 1, 2, 3, 4, 5, 6); list.insert(3, 100); checkCollection(list, 0, 1, 2, 100, 3, 4, 5, 6); list.insertMultiple(1, -1, 3); checkCollection(list, 0, -1, -1, -1, 1, 2, 100, 3, 4, 5, 6); list.clear(); assertEquals(0, list.size()); CHECK.order(list); list.add(0); checkCollection(list, 0); list.add(0); checkCollection(list, 0, 0); list.clear(); for (int i = 0; i < 100; i++) { list.add(i); checkCollection(list, ap(0, i + 1, 1)); } list.addAll(list); checkCollection(list.subList(0, 100), ap(0, 100, 1)); checkCollection(list.subList(100, 200), ap(0, 100, 1)); list.clear(); } } }
public void testIteratorRemove3() { for (WritableLongList list: createWritableLongLists(ap(0, 10, 1))) { WritableLongListIterator it = list.iterator(); it.next().next(); it.remove(); checkJustRemoved(it); assertEquals(2, it.nextValue()); it.move(7); assertEquals(9, it.value()); it.remove(); assertFalse(it.hasValue()); checkCollection(list, 0, 2, 3, 4, 5, 6, 7, 8); } }