public void testAdjustKeys() { for (LongIntListMap map : createMapsFromLists(keys, values)) { map.adjustKeys(1, 3, 1); LongList expectedKeys = LongArray.create(0, 3, 5, 6, 8); CHECK.order(map.keysIterator(0, map.size()), expectedKeys.iterator()); checkMap(map, expectedKeys, values); map.adjustKeys(1, 3, -2); expectedKeys = LongArray.create(0, 1, 3, 6, 8); CHECK.order(map.keysIterator(0, map.size()), expectedKeys.iterator()); checkMap(map, expectedKeys, values); try { map.adjustKeys(-1, 2, 5); fail(); } catch (IndexOutOfBoundsException ex) { } try { map.adjustKeys(1, 6, 5); fail(); } catch (IndexOutOfBoundsException ex) { } try { map.adjustKeys(1, 2, -1); fail(); } catch (IllegalArgumentException ex) { } try { map.adjustKeys(4, 5, -2); fail(); } catch (IllegalArgumentException ex) { } } }
@Override public void checkMap(LongIntListMap actualMap, LongList expectedKeys, IntList expectedValues) { super.checkMap(actualMap, expectedKeys, expectedValues); final LongArray keysArray = new LongArray(expectedKeys); final IntArray valuesArray = new IntArray(expectedValues); IntegersUtils.quicksort(keysArray.size(), LongFunctions.comparator(keysArray), new IntIntProcedure() { @Override public void invoke(int a, int b) { keysArray.swap(a, b); valuesArray.swap(a, b); } }); CHECK.order(keysArray, actualMap.keysAsList()); CHECK.order(LongCollections.asLongList(valuesArray), LongCollections.asLongList(actualMap.valuesAsList())); CHECK.order(actualMap.keysIterator(0, actualMap.size()), keysArray.iterator()); CHECK.order(actualMap.valuesIterator(0, actualMap.size()), valuesArray.iterator()); }