@Override public List<? extends LongIterator> get(long... values) { long start = 0, step = 0; int count = 0; if (values.length != 0) { start = values[0]; count = values.length; step = (count > 1) ? values[1] - values[0] : 1; } return Arrays.asList(LongProgression.arithmetic(start, count, step).iterator()); } }, LongIteratorSpecificationChecker.ValuesType.ARITHMETHIC);
public void testValuesSet() { List<Long> ints = LongProgression.arithmetic(0, 50).toList(); Collections.shuffle(ints); for (Long i : ints) { myMap.put(i, String.valueOf(i)); } long last = -1; for (String s : myMap.getValues()) { assertNotNull(s); long cur = toLong(s, -10); assertTrue(last + " " + cur, last < cur); last = cur; } }
public void testIterable() { List<Long> ints = LongProgression.arithmetic(0, 50).toList(); Collections.shuffle(ints); for (Long i : ints) { myMap.put(i, String.valueOf(i)); } int last = -1; for(LongObjIterator<String> it : myMap) { assertEquals(String.valueOf(it.left()), it.right()); long cur = toLong(it.right(), -10); assertTrue(last + " " + cur, last < cur); } }
public void testIndexOf() { for (WritableLongList list: createWritableLongLists( new LongArray(LongProgression.arithmetic(99, 100, -1)).extractHostArray())) { for (int i = 0; i < 100; i++) { assertEquals(99 - i, list.indexOf(i)); } } }
public void testTailIteratorSimple() { if (!isSortedSet()) return; for (LongSet set : createSets(arithmetic(1, 5, 2))) { LongSortedSet sortedSet = (LongSortedSet) set; for (int i = 0; i < 9; i++) { assertEquals(i + 1 - (i % 2), sortedSet.tailIterator(i).nextValue()); } } }
public void testToNativeArray() { int start = 10, step = 3, count = 31; long[] values = new long[count]; for (int i = 0; i < count; i++) values[i] = start + step * i; LongProgression list = LongProgression.arithmetic(start, count, step); for (int startIdx = 0; startIdx < count; startIdx++) { for (int endIdx = startIdx + 1; endIdx < count; endIdx++) { long[] expected = LongCollections.repeat(-1, count).toNativeArray(); long[] actual = LongCollections.repeat(-1, count).toNativeArray(); int len = endIdx - startIdx; System.arraycopy(values, startIdx, expected, startIdx, len); list.toNativeArray(startIdx, actual, startIdx, len); CHECK.order(actual, expected); } } } }
public void testTransformValuesChangingSortedState() { map.insertAll(new LongArray(arithmetic(0, 10)), I); map.transformValues(apply(swap(MOD), 3)); checkMapValuesEqualKeysMod(3); }
public void testRemoveRandom() { final int N_KEYS = 1000; int prime = 41; map.insertAllRo(arithmetic(0, N_KEYS, 3), apply(swap(MOD), prime)); LongArray removed = new LongArray(); for (int i = 0; i < N_KEYS / 10; ++i) { int k; while (true) { k = myRand.nextInt(N_KEYS)*3; if (!removed.contains(k)) { removed.add(k); break; } } map.remove(k); checkMapValuesEqualKeysMod(prime); } }
public void testRetainSimple() { checkRetain(LongArray.create(Long.MIN_VALUE), LongArray.create(Long.MIN_VALUE + 1), false); checkRetain(LongArray.create(Long.MIN_VALUE), LongArray.create(Long.MIN_VALUE + 1), true); checkRetain(LongArray.create(2, 3, 5, 6, 8, 9, 10, 13, 3, 4, 5, 3), LongArray.create(1, 4, 5, 6, 7, 8, 10, 15), false); checkRetain(LongArray.create(0, 1, 2, 3, 5, 3, 2, 1, -10), LongArray.create(0, 2, -10), false); checkRetain(LongProgression.arithmetic(0, 20, 1), LongProgression.arithmetic(1, 15, 2), true); checkRetain(LongArray.create(0, 1, 2, 3, 10), LongArray.create(0, 2, 10), true); }
public void testRemoveAllAtSorted() { LongArray a = new LongArray(LongProgression.arithmetic(0, 20)); LongCollections.removeAllAtSorted(a, IntArray.create(0, 3, 4, 7, 10, 11, 12, 13, 19)); CHECK.order(a.iterator(), 1, 2, 5, 6, 8, 9, 14, 15, 16, 17, 18); LongCollections.removeAllAtSorted(a, IntArray.create(1, 2, 3, 4, 9)); CHECK.order(a.iterator(), 1, 9, 14, 15, 16, 18); }
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 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 testNonInjectiveFunctionException() { map.insertAll(new LongArray(arithmetic(0, 10)), apply(MULT, 10)); map.transformValues(apply(ADD, 1)); for (int i = 0; i < map.size(); ++i) assertEquals(i*10+1, map.get(i)); try { map.transformKeys(new LongToLong() { public long invoke(long a) { return a + 1 + a%2; } }); fail(); } catch (LongTwoWayMap.NonInjectiveFunctionException ex) { assertEquals(3, ex.getDuplicateValue()); } }
public void testInsertAllSimple() { map.insertAll(LongArray.create(0, 3, 1, 4, 2), LongArray.create(0, 30, 10, 40, 20)); for (int i = 0; i < 5; ++i) assertEquals(i*10, map.get(i)); map.clear(); assertEquals(0, map.size()); assertTrue(map.isEmpty()); assertEquals(0, map.put(0, 0)); assertEquals(50, map.put(5, 50)); assertEquals(80, map.put(8, 80)); compare.order(map.getKeys().toNativeArray(), 0, 5, 8); compare.order(map.getValues().toNativeArray(), 0, 50, 80); map.insertAll(LongArray.create(3, 7, 1, 4, 9, 2, 6), LongArray.create(30, 70, 10, 40, 90, 20, 60)); compare.order(map.getKeys().toNativeArray(), arithmetic(0, 10).toNativeArray()); for (int i = 0; i < 10; ++i) assertEquals(i*10, map.get(i)); map.clear(); map.insertAllRo(LongProgression.arithmetic(0, 10), LongProgression.arithmetic(0, 10, 10)); for (int i = 0; i < 10; ++i) assertEquals(i*10, map.get(i)); }
public void testRemoveSimple() { map.insertAllRo(arithmetic(0, 10), apply(swap(MOD), 3)); map.remove(3); map.remove(5); map.remove(1); map.remove(2); assertFalse(map.containsAnyKeys(LongArray.create(1, 2, 3, 5))); assertEquals(6, map.size()); assertFalse(map.isEmpty()); checkMapValuesEqualKeysMod(3); }
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 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 testEnsureCapacity() { LongArray expected = new LongArray(LongProgression.arithmetic(0, 20, 1)); array = LongArray.copy(expected); assertEquals(20, array.getCapacity()); array.ensureCapacity(3); CHECK.order(array, expected); assertEquals(20, array.getCapacity()); array.ensureCapacity(25); CHECK.order(array, expected); assertEquals(40, array.getCapacity()); try { array.ensureCapacity(-1); fail("not caught IAE"); } catch (IllegalArgumentException ex) { } }
public void testTransformValuesNotChangingSortedState() { map.insertAll(new LongArray(arithmetic(0, 10)), apply(MULT, 10)); map.transformValues(apply(ADD, 1)); for (int i = 0; i < map.size(); ++i) assertEquals(i*10+1, map.get(i)); map.transformValues(new LongToLong() { public long invoke(long a) { return a - ((a - 1)/10)%2; } }); for (int i = 0; i < map.size(); ++i) assertEquals(i * 10 + (1 - (i % 2)), map.get(i)); map.transformValues(apply(MULT, 0)); for (int i = 0; i < map.size(); ++i) assertEquals(0, map.get(i)); }
public void testAddRemoveSimple2() { set.addAll(3, 1, 5, 2, 0, 4); LongList expected = LongProgression.arithmetic(0, 6); checkSet(set, expected); set.removeAll(expected.toNativeArray()); assertTrue(set.isEmpty()); set.clear(); set.addAll(1, 2, 5, 7, 8, 11, 14, 15); assertEquals(8, set.size()); set.remove(11); assertFalse(set.contains(11)); assertEquals(7, set.size()); set.remove(256); assertFalse(set.contains(256)); assertEquals(7, set.size()); set.removeAll(1,2,5); assertEquals(4, set.size()); }