@Override public List<LongListIterator> get(long... values) { List<? extends LongList> lists = createLongListVariants(values); List<LongListIterator> res = new ArrayList<LongListIterator>(lists.size()); for (LongList list : lists) { res.add(list.iterator()); } return res; } });
@Override public LongIterator get(LongArray... arrays) { return LongCollections.complementSorted(arrays[0], arrays[1]).iterator(); } }, new SetOperationsChecker.MinusGetter(), true, SORTED_UNIQUE, SORTED);
@Override public LongIterator get(LongArray... arrays) { return LongCollections.intersectionSortedUnique(arrays[0], arrays[1]).iterator(); } }, new SetOperationsChecker.IntersectionGetter(true), true, SORTED_UNIQUE);
@Override public LongIterator get(LongArray... arrays) { return LongCollections.unionSortedUnique(arrays[0], arrays[1]).iterator(); } }, new SetOperationsChecker.UnionGetter(), true, SORTED_UNIQUE);
@Override public void addAll(LongList values) { addAll(values.iterator()); }
public void testCreator() { LongProgression.Arithmetic progression = new LongProgression.Arithmetic(0, 5, 2); LongList expected = LongArray.create(0, 2, 4, 6, 8); CHECK.order(expected.iterator(), progression.iterator()); }
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 testInsertAt() { myMap.insertAt(2, 3, -1); LongList expectedKeys = LongArray.create(0, 2, 3, 4, 6, 8); LongList expectedValues= LongArray.create(1, 11, -1, 21, 31, 41); CHECK.order(myMap.keysIterator(0, myMap.size()), expectedKeys.iterator()); CHECK.order(myMap.valuesIterator(0, myMap.size()), expectedValues.iterator()); }
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 LongIterator get(LongArray... arrays) { set = createSet(arrays[0]); set.retain(arrays[1]); return isSortedSet() ? set.iterator() : toSorted(false, set).iterator(); } }, new SetOperationsChecker.IntersectionGetter(isSortedSet()), true, sortedStatus);
protected List<LongTreeSet> createSets(LongList sortedUniqueList) { set = new LongTreeSet(); set.addAll(sortedUniqueList); LongTreeSet set2 = new LongTreeSet(); set2.addAll(sortedUniqueList.iterator()); return Arrays.asList(set, set2, LongTreeSet.createFromSortedUnique(sortedUniqueList), LongTreeSet.createFromSortedUnique(sortedUniqueList, sortedUniqueList.size(), TO_ADD), LongTreeSet.createFromSortedUnique(sortedUniqueList, sortedUniqueList.size(), TO_REMOVE)); }
public void testSet() { myMap.setAt(0, -1, -10); LongList expectedKeys = LongArray.create(-1, 2, 4, 6, 8); LongList expectedValues= LongArray.create(-10, 11, 21, 31, 41); CHECK.order(myMap.keysIterator(0, myMap.size()), expectedKeys.iterator()); CHECK.order(myMap.valuesIterator(0, myMap.size()), expectedValues.iterator()); myMap.setKey(1, 3); try { myMap.setKey(1, 4); fail(); } catch (IllegalArgumentException ex) { } myMap.setValue(1, 100); expectedKeys = LongArray.create(-1, 3, 4, 6, 8); expectedValues= LongArray.create(-10, 100, 21, 31, 41); CHECK.order(myMap.keysIterator(0, myMap.size()), expectedKeys.iterator()); CHECK.order(myMap.valuesIterator(0, myMap.size()), expectedValues.iterator()); }
public void testGet() { long[] expected = {0, 1, 2, 5, 6, 7}; CHECK.order(indices.iterator(), decorator.getIndices().iterator()); CHECK.order(source.iterator(), decorator.getSource().iterator()); checkCollection(decorator, expected); }
public void testRemoveAllValues() { map.insertAllRo(LongProgression.arithmetic(0, 10), apply(swap(MOD), 3)); LongList notInMap; notInMap = map.removeAllValues(LongArray.create(2, 0)); compare.empty(notInMap.toNativeArray()); compare.order(map.getKeys().iterator(), 1, 4, 7); checkMapValuesEqualKeysMod(3); map.removeAllValues(LongArray.create(1)); assertEquals(0, map.size()); map.clear(); map.insertAllRo(LongProgression.arithmetic(0, 10, 2), apply(swap(MOD), 13)); // Important: specify one of the values not in the map notInMap = map.removeAllValues(LongArray.create(6, 7, 8, 9, 10)); compare.order(notInMap.iterator(), 7, 9); compare.order(map.getKeys().iterator(), 0, 2, 4, 12, 14, 16, 18); checkMapValuesEqualKeysMod(13); }
public void testSimple() { LongList[] lists = {LongList.EMPTY, new LongList.Single(10), LongArray.create(0, 1, 2), LongProgression.Arithmetic.range(3), null}; for (LongList list : lists) { assertEquals(0, comparator.compare(list, list)); } assertEquals(-1, comparator.compare(null, LongArray.create(0, 1, 2))); assertEquals(0, comparator.compare(lists[2], lists[3])); assertEquals(0, comparator.compare(lists[2], lists[2].iterator())); } }
public void testToSortedSimple() { int arrLength = 10; LongArray arr = new LongArray(LongProgression.arithmetic(0, arrLength, 1)); arr.add(arrLength++); for (int i = 0; i < arrLength; i++) { LongList expected = arr.subList(i, arr.size()); for (boolean uniqueStatus: new boolean[]{false, true}) { LongList actual = LongCollections.toSorted(uniqueStatus, arr.subList(i, arr.size()).iterator()); CHECK.order(actual, expected); actual = LongCollections.toSorted(uniqueStatus, arr.subList(i, arr.size())); CHECK.order(actual, expected); } } }
public void testPut() { myMap.clear(); for (int i = 4; 0 <= i; i--) { myMap.put(i*2, i * 10 + 1); } LongList expectedKeys = LongArray.create(0, 2, 4, 6, 8); WritableLongList expectedValues= LongArray.create(1, 11, 21, 31, 41); CHECK.order(myMap.keysIterator(0, myMap.size()), expectedKeys.iterator()); CHECK.order(myMap.valuesIterator(0, myMap.size()), expectedValues.iterator()); myMap.put(0, -1); expectedValues.set(0, -1); CHECK.order(myMap.valuesIterator(0, myMap.size()), expectedValues.iterator()); }
public void testAdd() { LongSetBuilder b = new LongSetBuilder(); assertTrue(b.isEmpty()); for (int i = 0; i < 8; i++) { b.add(i * 2); } assertFalse(b.isEmpty()); b.addAll(10, 100, 200); b.addAll(LongArray.create(-5, 9, 3)); b.addAll(LongArray.create(7, 15, 4).iterator()); LongArray expected = LongArray.create(); for (int i = 0; i < 8; i++) { expected.add(i * 2); } expected.addAll(10, 100, 200, -5, 9, 3, 7, 15, 4); expected.sortUnique(); LongList collection = b.toList(); CHECK.order(collection.iterator(), expected.iterator()); }
public void testLimit() throws Exception { LongIterator it = limit(LongArray.create(0, 1, 2), 2); CHECK.order(it, 0, 1); for (int i = 0; i < 10; i++) { it = limit(LongCollections.repeat(5, i * 20), i * 10); checkNoValue(it); CHECK.order(LongCollections.repeat(5, i * 10).iterator(), it); it = limit(LongProgression.arithmetic(0, i * 20, 1).iterator(), i * 10); checkNoValue(it); CHECK.order(LongProgression.arithmetic(0, i * 10, 1).iterator(), it); } assertFalse(limit(LongIterator.EMPTY, 0).hasValue()); assertFalse(limit(LongIterator.EMPTY, -1).hasValue()); assertFalse(limit(LongIterator.EMPTY, -10).hasValue()); }
public void testIterator() { LongArray keys = new LongArray(range(0, 10, 1)); LongArray values = new LongArray(LongCollections.map(SQR, range(10, 0, -1))); for (LongLongIterator it : new LongLongPairIterator(keys, values)) { map.put(it.left(), it.right()); } CHECK.order(map.keysIterator(), keys.iterator()); CHECK.order(LongCollections.toSortedUnique(values).iterator(), map.valuesIterator()); LongLongIterator mapIt = map.iterator(), it = new LongLongPairIterator(keys, values); while (mapIt.hasNext()) { assertTrue(it.hasNext()); mapIt.next(); it.next(); assertEquals(it.left(), mapIt.left()); assertEquals(it.right(), mapIt.right()); } } }