@Override protected List<LongArray> createWritableLongLists(long... values) { List<LongArray> res = new ArrayList<LongArray>(); LongArray arr = LongArray.copy(values); res.add(arr); arr = new LongArray(values.length * 2); arr.addAll(values); res.add(arr); arr = new LongArray(values.length * 2); arr.addAll(values); arr.addAll(generateRandomLongArray(values.length, UNORDERED)); arr.removeRange(values.length, values.length * 2); res.add(arr); return res; }
public LongIterable get(LongArray ... arrays) { LongArray expected = new LongArray(); for (LongArray array : arrays) { expected.addAll(array); } expected.sortUnique(); return expected; } }
public void testToBoundedString() { LongArray array = new LongArray(); array.addAll(LongIterators.range(10)); checkToBoundedString("(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)", 5, array); array.add(10); checkToBoundedString("[11] (0, 1, 2, 3, 4, ..., 6, 7, 8, 9, 10)", 5, array); array.addAll(LongIterators.range(11, 21)); checkToBoundedString("[21] (0, 1, 2, 3, 4, ..., 16, 17, 18, 19, 20)", 5, array); array.addAll(LongIterators.range(21, 40)); StringBuilder expected = new StringBuilder().append("(0"); for (int i = 1; i < 40; i++) { expected.append(", ").append(i); } expected.append(')'); checkToBoundedString(expected.toString(), 20, array); array = LongArray.create(0, 1, 2, 3, 4); checkToBoundedString("[5] (0, 1, ..., 3, 4)", 2, array); }
protected void checkCollectionM(LongList collection, long[]... ints) { LongArray t = new LongArray(); for (long[] ar : ints) { t.addAll(ar); } checkCollection(collection, t.toNativeArray()); }
public void testArray_RemoveSubsequentDuplicates() { myArray.addAll(1, 1, 2); myArray.sortUnique(); checkCollection(myArray, 1, 2); myArray.clear(); myArray.addAll(1, 2, 2, 3); myArray.sortUnique(); checkCollection(myArray, 1, 2, 3); myArray.clear(); myArray.addAll(1, 2, 3, 3); myArray.sortUnique(); checkCollection(myArray, 1, 2, 3); myArray.clear(); myArray.addAll(1, 1, 2, 2, 3, 3); myArray.sortUnique(); checkCollection(myArray, 1, 2, 3); }
@Override public LongIterable get(LongArray... arrays) { assert arrays[0].isSortedUnique() && arrays[1].isSortedUnique(); LongArray expected = new LongArray(arrays[0].size()); expected.addAll(new LongMinusIterator(arrays[0], arrays[1])); expected.addAll(new LongMinusIterator(arrays[1], arrays[0])); expected.sortUnique(); return expected; } }
protected void checkList(LongList collection, long[]... v) { LongArray r = new LongArray(); for (long[] ints : v) { r.addAll(ints); } long[] expected = r.toNativeArray(); CHECK.order(collection.iterator(), expected); }
public void testSetRangeAndRemoveRangeComplex() { int[][] countsArray = {{1, 1, 1, 1, 1}, {1, 2, 3, 4, 5}, {5, 4, 3, 2, 1}, {2, 1, 2, 1, 2}}; long[][] valuesArray = {{0, 10, 20, 30, 40}, {-1, 1, -1, 1, -1}, {0, 1, 2, 0, 3}}; for (int[] counts : countsArray) { int size = 0; LongArray values = new LongArray(size); for (int count : counts) size += count; for (long[] values0 : valuesArray) { values.clear(); assert values0.length == counts.length; for (int j = 0; j < counts.length; j++) { values.addAll(LongCollections.repeat(values0[j], counts[j])); } checkSetRangeAndRemoveRange(values); } } }
protected void checkSet(LongList collection, long[]... v) { LongArray r = new LongArray(); for (long[] ints : v) { r.addAll(ints); } r.sortUnique(); long[] expected = r.toNativeArray(); CHECK.order(collection.iterator(), expected); }
@Override public long[] generateValues(Random random, int size) { LongArray array = generateRandomLongArray(random, size, SortedStatus.SORTED); array.addAll(array.get(IntProgression.range(0, size, 3))); array.sort(); return array.toNativeArray(); }
public void testKeySet() { myMap.put(0, "0"); myMap.put(100, "100"); myMap.put(228, "228"); checkSet(myMap.keySet(), LongArray.create(0, 100, 228)); assertEquals(myMap.values(), Arrays.asList("0", "100", "228")); LongArray expected = new LongArray(10000); expected.addAll(0, 100, 228); for (int i = 0; i < 10000; i++) { long value = myRand.nextInt(); expected.add(value); myMap.put(value, Long.toString(value)); } expected.sortUnique(); checkSet(myMap.keySet(), expected); }
public void testSimple() { LongArray a = LongArray.create(1, 2, 5, 10), b = LongArray.create(-3, 2, 3, 4, 11), expected = LongArray.copy(a); expected.addAll(b); expected.sortUnique(); LongArray union = new LongArray(new LongUnionIteratorOfTwo(a, b)); CHECK.order(union, expected); }
public void testIterator() { LongArray source = LongArray.create(10,13,15,14,11,12,16,17,18), expected = LongArray.create(10,15,14,12,16,18), result = new LongArray(); IntArray indices = IntArray.create(1, 4, 7); prepareSortedIndices(indices); LongListRemovingDecorator tst2 = createFromPrepared(source, indices); result.addAll(tst2.iterator()); assertEquals(expected, result); }
public void testRetainWithDuplicates() { int arraySize = 100, valuesSize = 10; for (int attempt = 0; attempt < 20; attempt++) { array = generateRandomLongArray(arraySize, SORTED, arraySize * 3 / 2); LongArray values = generateRandomLongArray(valuesSize, UNORDERED, arraySize * 3 / 2); values.addAll(values.get(range(0, values.size(), 2))); values.shuffle(myRand); checkRetain(array, values, false); values.sort(); checkRetain(array, values, true); } }
public void testRemoveSorted() { array = LongArray.create(0, 20, 21, 30, 35, 80); assertTrue(array.removeSorted(20)); CHECK.order(LongArray.create(0, 21, 30, 35, 80), array); array.clear(); assertFalse(array.removeSorted(0)); array.addAll(0, 1, 1, 1, 2, 10); assertTrue(array.removeSorted(1)); CHECK.order(array, 0, 1, 1, 2, 10); }
public void testSetRangeSimple2() { int count = 4; LongArray values = LongArray.create(0, 2, 4); LongArray expected = new LongArray(values.size() * count); for (int i = 0; i < values.size(); i++) { expected.addAll(LongCollections.repeat(values.get(i), count)); } list.addAll(expected); CHECK.order(expected, list); int[][] valuesForSet = {{0, 1, 1}, {1, 2, 1}, {4, 9, -1}}; for (int[] vals : valuesForSet) { list.setRange(vals[0], vals[1], vals[2]); expected.setRange(vals[0], vals[1], vals[2]); CHECK.order(expected, list); } }
public void testCreateSimple() { int count = 4; LongArray values = LongArray.create(0, 2, 4); LongArray expected = new LongArray(values.size() * count); for (int i = 0; i < values.size(); i++) { expected.addAll(LongCollections.repeat(values.get(i), count)); } list = LongSameValuesList.create(values, IntCollections.repeat(4, values.size())); CHECK.order(expected, list); expected = LongArray.create(1, 1, 2, 2, 3, 3, 3, 3, 3, 4); list = LongSameValuesList.create(expected); CHECK.order(expected, list); }
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 testCreate() { LongArray myArray = new LongArray(); myArray.addAll(0, 1, 2, 3, 4, 5, 6); WritableLongListRemovingDecorator rem = WritableLongListRemovingDecorator.createFromUnsorted(myArray, 0, 4, 1, 5); checkCollection(rem, 2, 3, 6); checkRemovedIndexes(rem, 0, 1, 4, 5); assertEquals(4, rem.getRemoveCount()); rem = WritableLongListRemovingDecorator.createFromUnsorted(myArray, 2, 6, 1); checkCollection(rem, 0, 3, 4, 5); checkRemovedIndexes(rem, 1, 2, 6); assertEquals(3, rem.getRemoveCount()); rem = WritableLongListRemovingDecorator.createFromUnsorted(myArray, 2, 6, 1, 2); checkCollection(rem, 0, 3, 4, 5); checkRemovedIndexes(rem, 1, 2, 6); assertEquals(3, rem.getRemoveCount()); }
public void testAddAll() { LongArray expected = LongArray.create(ap(1, 10, 2)); set.addAll(expected); checkSet(set, expected); expected.addAll(ap(0, 10, 2)); set.addAll(expected.toNativeArray()); expected.sortUnique(); checkSet(set, expected); set.removeAll(expected); assertTrue(set.isEmpty()); expected = generateRandomLongArray(10, UNORDERED); set.addAll(expected.iterator()); expected.sortUnique(); checkSet(set, expected); }