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 testBoundary() { for (WritableLongList list: empty()) { list.apply(0, 0, null); list.clear(); try { list.get(0); fail(); } catch (IndexOutOfBoundsException e) { } list.remove(0); list.removeRange(0, 0); assertEquals(list, list.subList(0, 0)); list.toNativeArray(0, new long[0], 0, 0); } }
protected void checkExpand(long[] expected, int index, int count, WritableLongList checked) { assert index <= expected.length; checked.expand(index, count); assertEquals(expected.length + count, checked.size()); LongListIterator it = checked.iterator(); for (int i = 0; i < index; i++) { assertEquals(expected[i], it.nextValue()); } it.move(count); for (int i = index; i < expected.length; i++) { assertEquals(expected[i], it.nextValue()); } }
public void testRemoveAll() { for (WritableLongList list: empty()) { long[] values = {2, 0, 2, 1, 2, 2, 2, 2, 3, 2}; list.addAll(values); CHECK.order(list.iterator(), values); list.removeAll(); list.removeAll(2); CHECK.order(list.iterator(), 0, 1, 3); list.removeAll(2); CHECK.order(list.iterator(), 0, 1, 3); list.removeAll(0, 3); CHECK.order(list.iterator(), 1); list.removeAll(1); CHECK.empty(list); } }
12, 2, 40, -1, 25, Long.MIN_VALUE); assert sourceAdd.size() == sourceRemove.size() : sourceAdd.size() + " " + sourceRemove.size(); int size = sourceAdd.size(); WritableLongList expected = new LongArray(); LongIterator iiAdd = sourceAdd.iterator(); LongIterator iiRemove = sourceRemove.iterator(); for (int i = 0; i < size; i++) { if (stateCount >= 0) { set.add(iiAdd.nextValue()); expected.add(iiAdd.value()); } else { long value = iiRemove.nextValue(); set.remove(value); assertFalse(set.contains(value)); expected.removeAll(iiRemove.value()); assertEquals(expected.size(), set.size()); expected.sortUnique(); checkSet(set, expected);
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 testGetNextDifferentValueIndex2() { for (WritableLongList list: empty()) { list.insertMultiple(0, 1, 10); list.insert(10, 2); list.insertMultiple(11, 1, 5); list.insertMultiple(16, 3, 3); assertEquals("for index 0", 10, list.getNextDifferentValueIndex(0)); assertEquals("for index 5", 10, list.getNextDifferentValueIndex(5)); assertEquals("for index 9", 10, list.getNextDifferentValueIndex(9)); assertEquals("for index 10", 11, list.getNextDifferentValueIndex(10)); assertEquals("for index 11", 16, list.getNextDifferentValueIndex(11)); assertEquals("for index 16", list.size(), list.getNextDifferentValueIndex(16)); assertEquals("for index 18", list.size(), list.getNextDifferentValueIndex(18)); // check for IOOBE try { list.getNextDifferentValueIndex(-1); fail("not caught OOBE for index - 1"); } catch(IndexOutOfBoundsException ex) { } try { list.getNextDifferentValueIndex(list.size()); fail("not caught OOBE for index = size"); } catch(IndexOutOfBoundsException ex) { } } }
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 testIteratorSkip() { for (WritableLongList list: empty()) { for (int i = 0; i < 10000; i++) list.add(i); WritableLongListIterator ii = list.iterator(); for (int i = 0; i < 100; i++) { assertTrue(ii.hasNext()); assertEquals(100 * i, ii.nextValue()); ii.move(99); } assertFalse(ii.hasNext()); } }
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 testReverse() { testReverse(new long[]{}, new long[]{}); testReverse(new long[]{4, 4, 1, 2, 2, 2, 3, 3, 3, 3}, new long[]{3, 3, 3, 3, 2, 2, 2, 1, 4, 4}); testReverse(new long[]{4, 4, 1, 2, 2, 2, 0, 0, 0, 0}, new long[]{0, 0, 0, 0, 2, 2, 2, 1, 4, 4}); testReverse(new long[]{2, 4, 4, 5, 5, 5, 7, 7, 7, 7}, new long[]{7, 7, 7, 7, 5, 5, 5, 4, 4, 2}); testReverse(new long[]{2, 2, 3, 3, 3}, new long[]{3, 3, 3, 2, 2}); testReverse(new long[]{1, 1, 1}, new long[]{1, 1, 1}); testReverse(new long[]{1, 1, 0}, new long[]{0, 1, 1}); testReverse(new long[]{0}, new long[]{0}); testReverse(new long[]{0, 1, 3, 6, 10, 15, 21, 28, 36}, new long[]{36, 28, 21, 15, 10, 6, 3, 1, 0}); testReverse(new long[]{0, 1, 3, 6, 10, 15, 21, 28, 36}, new long[]{36, 28, 21, 15, 10, 6, 3, 1, 0}); testReverse(new long[]{0, 0, 1, 2, 2, 2, 3, 3, 3, 3}, new long[]{3, 3, 3, 3, 2, 2, 2, 1, 0, 0}); testReverse(new long[]{0, 0, 1, 2, 2, 2, 0, 0, 0, 0}, new long[]{0, 0, 0, 0, 2, 2, 2, 1, 0, 0}); testReverse(new long[]{0, 0, 0}, new long[]{0, 0, 0}); testReverse(new long[]{0, 0, 0, 1, 1}, new long[]{1, 1, 0, 0, 0}); testReverse(new long[]{0, 0, 0, 0, 1, 1, 0}, new long[]{0, 1, 1, 0, 0, 0, 0}); // have to use toNativeArray() instead of extractHostArray(), because of in the myArray may be duplicates for (WritableLongList list: createWritableLongLists(generateRandomLongArray(20, SORTED_UNIQUE, 200).toNativeArray())) { list.reverse(); for (int i = 1; i < list.size(); i++) { assertFalse(list.get(i - 1) <= list.get(i)); } } }
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 testInsertAll() { for (WritableLongList list: empty()) { list.addAll(0); list.insertAll(1, LongArray.create(2, 4, 6).iterator()); checkCollection(list, 0, 2, 4, 6); list.insertAll(2, LongArray.create(-5, -10, -15)); checkCollection(list, 0, 2, -5, -10, -15, 4, 6); list.insertAll(0, LongArray.create(0, 99, 99, 0), 1, 2); checkCollection(list, 99, 99, 0, 2, -5, -10, -15, 4, 6); } }
public void testExpandException() { for (int size = 0; size < 5; size++) { for (WritableLongList list: createWritableLongLists( LongCollections.repeat(10, size).toNativeArray())) { try { list.expand(list.size() + 1, 0); fail(); } catch (IndexOutOfBoundsException ex) {} try { list.expand(-1, 0); fail(); } catch (IndexOutOfBoundsException ex) {} try { list.expand(0, -10); fail(); } catch (IllegalArgumentException ex) {} if (size > 0) { list.expand(1, 0); CHECK.order(LongCollections.repeat(10, size), list); } } } }
case 0: { int index = i / 3; assertTrue(list.addSorted(value)); expected.insert(index, value); CHECK.order(expected, list); expected.removeAt(index); list.removeAt(index); break; assertFalse(list.addSorted(value)); CHECK.order(expected, list); break; assertTrue(list.addSorted(value)); int index = (i + 1) / 3; expected.insert(index, value); CHECK.order(expected, list); expected.removeAt(index); list.removeAt(index); break;
public void testSimpleResize() { long[] values0 = {-1, 0, 10, -10, 20, 30}; LongArray values = new LongArray(values0); LongArray toAdd = LongArray.create(0, -4, -10, 20); LongList expected = LongCollections.concatLists(values, toAdd); for (WritableLongList list : createWritableLongLists(values0)) { CHECK.order(values, list); list.addAll(toAdd); CHECK.order(expected, list); } LongList valuesList = LongProgression.range(1024); values0 = valuesList.toNativeArray(); long[] expected0 = LongCollections.collectLists(valuesList, new LongList.Single(1025)).extractHostArray(); for (WritableLongList list : createWritableLongLists(values0)) { list.add(1025); CHECK.order(list, expected0); } }