LongSparseLongArrayTestpublic class LongSparseLongArrayTest extends TestCase Tests for {@link LongSparseLongArray}. |
Fields Summary |
---|
private static final String | TAG |
Methods Summary |
---|
private static E | getKeyAtIndex(java.util.Map map, int index)
final Iterator<E> keys = map.keySet().iterator();
for (int i = 0; i < index; i++) {
keys.next();
}
return keys.next();
| public void | testFuzz()
final Random r = new Random();
final HashMap<Long, Long> map = new HashMap<Long, Long>();
final LongSparseLongArray array = new LongSparseLongArray(r.nextInt(128));
for (int i = 0; i < 10240; i++) {
if (r.nextBoolean()) {
final long key = r.nextLong();
final long value = r.nextLong();
map.put(key, value);
array.put(key, value);
}
if (r.nextBoolean() && map.size() > 0) {
final int index = r.nextInt(map.size());
final long key = getKeyAtIndex(map, index);
map.remove(key);
array.delete(key);
}
}
Log.d(TAG, "verifying a map with " + map.size() + " entries");
for (Map.Entry<Long, Long> e : map.entrySet()) {
final long key = e.getKey();
final long value = e.getValue();
assertEquals(value, array.get(key));
}
| public void | testMiddleInsert()
final LongSparseLongArray array = new LongSparseLongArray(5);
for (int i = 0; i < 48; i++) {
final long value = 1 << i;
array.put(value, value);
}
final long special = (1 << 24) + 5;
array.put(special, 1024);
for (int i = 0; i < 48; i++) {
final long value = 1 << i;
assertEquals(value, array.get(value, -1));
assertEquals(-1, array.get(-value, -1));
}
assertEquals(1024, array.get(special, -1));
| public void | testSimplePut()
final LongSparseLongArray array = new LongSparseLongArray(5);
for (int i = 0; i < 48; i++) {
final long value = 1 << i;
array.put(value, value);
}
for (int i = 0; i < 48; i++) {
final long value = 1 << i;
assertEquals(value, array.get(value, -1));
assertEquals(-1, array.get(-value, -1));
}
| public void | testSimplePutBackwards()
final LongSparseLongArray array = new LongSparseLongArray(5);
for (int i = 47; i >= 0; i--) {
final long value = 1 << i;
array.put(value, value);
}
for (int i = 0; i < 48; i++) {
final long value = 1 << i;
assertEquals(value, array.get(value, -1));
assertEquals(-1, array.get(-value, -1));
}
|
|