ByteString test failure bug
Motivation: There is an error in the ByteString test logic which is resulting in test failures. Modifications: - Fix the loop iteration to use the loop iteration variable instead of a fixed index. Result: Tests are less buggy.
This commit is contained in:
parent
02e94090df
commit
c88de88c4d
@ -54,25 +54,32 @@ public class ByteStringTest {
|
|||||||
bByteString = new ByteString(b, bOffset, length, false);
|
bByteString = new ByteString(b, bOffset, length, false);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
final int end = aOffset + length;
|
||||||
// Find an element that can be decremented
|
// Find an element that can be decremented
|
||||||
for (i = 1; i < length; ++i) {
|
for (i = aOffset + 1; i < end; ++i) {
|
||||||
if (a[aOffset + 1] > Byte.MIN_VALUE) {
|
if (a[i] > Byte.MIN_VALUE) {
|
||||||
--a[aOffset + 1];
|
--a[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (i == end) {
|
||||||
|
throw new IllegalStateException("Couldn't find an index to decrement, all random numbers Byte.MIN_VALUE");
|
||||||
|
}
|
||||||
lessThanAByteString = new ByteString(a, aOffset, length, true);
|
lessThanAByteString = new ByteString(a, aOffset, length, true);
|
||||||
++a[aOffset + i]; // Restore the a array to the original value
|
++a[i]; // Restore the a array to the original value
|
||||||
|
|
||||||
// Find an element that can be incremented
|
// Find an element that can be incremented
|
||||||
for (i = 1; i < length; ++i) {
|
for (i = aOffset + 1; i < end; ++i) {
|
||||||
if (a[aOffset + 1] < Byte.MAX_VALUE) {
|
if (a[i] < Byte.MAX_VALUE) {
|
||||||
++a[aOffset + 1];
|
++a[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (i == end) {
|
||||||
|
throw new IllegalStateException("Couldn't find an index to increment, all random numbers Byte.MAX_VALUE");
|
||||||
|
}
|
||||||
greaterThanAByteString = new ByteString(a, aOffset, length, true);
|
greaterThanAByteString = new ByteString(a, aOffset, length, true);
|
||||||
--a[aOffset + i]; // Restore the a array to the original value
|
--a[i]; // Restore the a array to the original value
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user