public void testIndexOf() { int arrayLength = 1000; int maxValue = Integer.MAX_VALUE; IntArray res = new IntArray(arrayLength); int[] intArr = new int[arrayLength]; for (int i = 0; i < arrayLength; i++) { int val = myRand.nextInt(maxValue); res.add(val); intArr[i] = val; } for (int i = 0; i < arrayLength; i++) { int val = res.get(i); assertEquals(res.indexOf(val), IntCollections.indexOf(val, intArr)); } }
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()); }
@Override public void testHashCode() { int attemptsCount = 10, shuffleCount = 10; int sizeMax = 600, step = 50; for (int attempt = 0; attempt < attemptsCount; attempt++) { for (int size = step; size < sizeMax; size += step) { LongArray keys = generateRandomLongArray(size, SORTED_UNIQUE); IntArray values = generateRandomIntArray(keys.size(), UNORDERED); int expectedHash = 0; for (int i = 0; i < size; i++) { expectedHash += IntegersUtils.hash(keys.get(i)) + (new Integer(values.get(i))).hashCode(); } for (WritableLongObjMap<Integer> map0 : createObjMapsFromLists(keys, values.toList())) { assertEquals(expectedHash, map0.hashCode()); } IntArray indices = new IntArray(IntProgression.range(size)); for (int i = 0; i < shuffleCount; i++) { map = createMap(); map.putAll(keys.get(indices), values.get(indices)); assertEquals(expectedHash, map.hashCode()); indices.shuffle(myRand); } } } } }
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); } }
@Override public void testHashCode() { int attemptsCount = 10, shuffleCount = 10; int sizeMax = 600, step = 50; for (int attempt = 0; attempt < attemptsCount; attempt++) { for (int mSize = step; mSize < sizeMax; mSize += step) { LongArray keys = generateRandomLongArray(mSize, SORTED_UNIQUE); int size = keys.size(); IntArray values = generateRandomIntArray(size, UNORDERED); int expectedHash = 0; for (int i = 0; i < size; i++) { expectedHash += IntegersUtils.hash(keys.get(i)) + IntegersUtils.hash(values.get(i)); } for (T map0 : createMapsFromLists(keys, values)) { assertEquals(expectedHash, map0.hashCode()); } IntArray indices = new IntArray(IntProgression.range(size)); for (int i = 0; i < shuffleCount; i++) { map = createMap(); map.putAll(keys.get(indices), values.get(indices)); assertEquals(expectedHash, map.hashCode()); indices.shuffle(myRand); } } } }
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()); } }
prepareSortedIndices(indices); for (int j = 0; j < indices.size(); j++) { resArray.removeAt(indices.get(j));
public void testGet() { for (int attempt = 0; attempt < 10; attempt++) { long[] values = generateRandomLongArray(1000, UNORDERED).extractHostArray(); for (LongList list: createLongListVariants(values)) { if (!(list instanceof AbstractLongList)) return; IntArray indices = generateRandomIntArray(100, UNORDERED, 0, 1000); AbstractLongList abstractList = (AbstractLongList)list; LongList actual = abstractList.get(indices); for (int j = 0; j < actual.size(); j++) { assertEquals(abstractList.get(indices.get(j)), actual.get(j)); } } } }
public void testRandomCreateFromSorted() { int arrLength = 100; int indicesLength = 50; int maxValue = 1000; LongList base = generateRandomLongArray(arrLength, UNORDERED, maxValue); for (int test = 0; test < 20; test++) { IntArray indices = generateRandomIntArray(indicesLength, SORTED_UNIQUE, arrLength); LongArray expected = LongArray.copy(base); for (int i = indices.size() - 1; i >= 0; i--) { int val = indices.get(i); expected.removeRange(val, val + 1); } WritableLongListRemovingDecorator arr = WritableLongListRemovingDecorator.createFromSorted(base, indices); CHECK.order(arr.iterator(), expected.iterator()); } }
expected.addAll(LongCollections.repeat(values.get(j), counts.get(j)));