public void testNoSuchElementExceptionCase() { LongArray list = LongArray.create(2, 3, 9); IntListIterator indices = IntArray.create(0, 2).iterator(); LongListIndexedIterator res = new LongListIndexedIterator(list, indices); // check for NSEE try { res.value(); fail("not caught NSEE"); } catch(NoSuchElementException ex) { } } }
public void setUp() throws Exception { super.setUp(); IntIterator arr1 = IntArray.create(1, 2, 3, 4, 5).iterator(); LongIterator arr2 = LongArray.create(5, 10, 15, 20, 25).iterator(); res = IntLongIterators.pair(arr1, arr2); }
public void testSimpleCase() { LongArray list = LongArray.create(2, 3, 9); IntListIterator indices = IntArray.create(0, 2).iterator(); LongListIndexedIterator res = new LongListIndexedIterator(list, indices); CHECK.order(LongArray.create(2, 9).iterator(), res); }
public void testEmptyCase() { LongArray list = LongArray.create(2, 3, 9); IntIterator indices = IntArray.create().iterator(); LongIndexedIterator res = new LongIndexedIterator(list, indices); CHECK.order(LongArray.create().iterator(), res); }
public void testSimpleCase() { LongArray list = LongArray.create(2, 3, 9); IntIterator indices = IntArray.create(0, 2).iterator(); LongIndexedIterator res = new LongIndexedIterator(list, indices); CHECK.order(LongArray.create(2, 9).iterator(), res); list = LongArray.create(1, 2, 3, 4, 5); indices = IntArray.create(0, 2, 4).iterator(); res = new LongIndexedIterator(list, indices); CHECK.order(LongArray.create(1, 3, 5).iterator(), res); }
public void testNoSuchElementExceptionCase() { LongArray list = LongArray.create(2, 3, 9); IntIterator indices = IntArray.create(0, 2).iterator(); LongIndexedIterator res = new LongIndexedIterator(list, indices); while (res.hasNext()) { res.nextValue(); } try { res.nextValue(); fail("not caught NSEE"); } catch(NoSuchElementException ex) { } }
public void testRandomCase() { int arrayLength = 1000; int indicesLength = 100; int maxValue = Integer.MAX_VALUE; LongArray list = LongArray.create(); for ( int i = 0; i < arrayLength; i++) { list.add((long) myRand.nextInt(maxValue)); } IntArray arrayIndexes = IntArray.create(); for ( int i = 0; i < indicesLength; i++) { arrayIndexes.add(myRand.nextInt(arrayLength)); } LongArray expected = LongArray.create(); for ( int i = 0; i < indicesLength; i++) { expected.add(list.get(arrayIndexes.get(i))); } LongIndexedIterator res = new LongIndexedIterator(list, arrayIndexes.iterator()); CHECK.order(res, expected.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 testRandomCreateFromSorted() { int arrLength = 100; int indicesLength = 50; int maxValue = 1000; LongArray base = generateRandomLongArray(arrLength, UNORDERED, maxValue); for (int test = 0; test < 20; test++) { IntArray indices = generateRandomIntArray(indicesLength, SORTED_UNIQUE, arrLength); LongArray expected = LongArray.copy(base); expected.removeAllAtSorted(indices.iterator()); prepareSortedIndices(indices); LongListRemovingDecorator arr = createFromPrepared(base, indices); CHECK.order(arr.iterator(), expected.iterator()); } }
private static void testRevPerm(IntArray perms) { IntArray rev = new IntArray(perms); IntegersUtils.reversePerm(rev); int n = perms.size(); IntArray e = new IntArray(n); for (int i = 0; i < n; ++i) { e.add(perms.get(rev.get(i))); } CHECK.order(IntProgression.arithmetic(0, n).iterator(), e.iterator()); }
public void testRemoveAllAtSorted() { int arSize = 100; int indicesSize = 10; int attempts = 10; for (int attempt = 0; attempt < attempts; attempt++) { array = generateRandomLongArray(arSize, UNORDERED); IntArray indices = generateRandomIntArray(indicesSize, SORTED_UNIQUE, array.size()); if (attempt % 2 == 0) { indices.add(indices.get(indices.size() / 2) + 1); indices.sortUnique(); } LongArray expected = LongArray.copy(array); for (int i = indices.size() - 1; i >= 0; i--) { expected.removeAt(indices.get(i)); } array.removeAllAtSorted(indices.iterator()); CHECK.order(array, expected); } }
public void testValueComplexCase() { IntArray keys = new IntArray(IntProgression.arithmetic(0, 1000, 1)); LongArray values0 = new LongArray(LongProgression.arithmetic(0, 1000, 1)); LongArray values = new LongArray(values0.toNativeArray()); values.apply(0, 1000, new LongToLong() { @Override public long invoke(long a) { return a * a - a; } }); res = IntLongIterators.pair(keys.iterator(), values.iterator()); for (int i = 0; i < 1000; i++) { res.next(); int v1 = res.left(); long v2 = res.right(); assertEquals(i, v1); assertEquals(i * i - i, v2); } } }
@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()); }
public void testListOperationsCase() { LongArray list = LongArray.create(1, 2, 3, 4, 5); IntListIterator indices = IntArray.create(0, 2, 4).iterator(); LongListIndexedIterator res = new LongListIndexedIterator(list, indices); // check .get assertEquals(3, res.get(2)); try { res.index(); fail("caught NSEE"); } catch (NoSuchElementException ex) { } for(int i = 0; i < 3; i++) { res.next(); assertEquals(i, res.index()); } for(int i = 2; i > 0; i--) { assertEquals(i, res.index()); res.move(-1); } for(int i = 0; i < 2; i++) { assertEquals(i, res.index()); res.move(1); } assertEquals(2, res.index()); }