GP-0: Test fixes

This commit is contained in:
Dan
2021-11-26 10:25:30 -05:00
parent 060f14673c
commit ef71c697a2
2 changed files with 10 additions and 6 deletions
@@ -215,7 +215,7 @@ public class SemisparseByteArray {
if (length < 0) {
throw new IllegalArgumentException("length: " + length);
}
if (loc + length < loc) {
if (Long.compareUnsigned(loc + length, loc) < 0) {
throw new IndexOutOfBoundsException("given offset and length would exceed ULONG_MAX");
}
UnsignedLong uLoc = UnsignedLong.fromLongBits(loc);
@@ -32,10 +32,14 @@ public class SemisparseByteArrayTest {
private static final String HELLO_WORLD = "Hello, World!";
protected static final byte[] HW = HELLO_WORLD.getBytes();
protected static Range<UnsignedLong> makeRange(long lower, long upper) {
protected static Range<UnsignedLong> rngClosedOpen(long lower, long upper) {
return Range.closedOpen(UnsignedLong.fromLongBits(lower), UnsignedLong.fromLongBits(upper));
}
protected static Range<UnsignedLong> rngClosed(long lower, long upper) {
return Range.closed(UnsignedLong.fromLongBits(lower), UnsignedLong.fromLongBits(upper));
}
@Test
public void testSingles() {
SemisparseByteArray cache = new SemisparseByteArray();
@@ -43,16 +47,16 @@ public class SemisparseByteArrayTest {
cache.putData(0, HW, 0, 1);
exp.clear();
exp.add(makeRange(0, 1));
exp.add(rngClosedOpen(0, 1));
assertEquals(exp, cache.getInitialized(0, HW.length + 7));
exp.clear();
exp.add(makeRange(1, HW.length));
exp.add(rngClosed(1, HW.length - 1));
assertEquals(exp, cache.getUninitialized(0, HW.length - 1));
cache.putData(2, HW, 2, 1);
exp.clear();
exp.add(makeRange(1, 2));
exp.add(makeRange(3, HW.length));
exp.add(rngClosedOpen(1, 2));
exp.add(rngClosed(3, HW.length - 1));
assertEquals(exp, cache.getUninitialized(0, HW.length - 1));
cache.putData(11, HW, 11, 2);