set flag ByteArraysPartialInputStream_debug. sclass Test_ByteArraysPartialInputStream { ByteArraysPartialInputStream stream; int n = 1000; byte[] data; void writeInRandomRanges(byte[] data) ctex { for (r : splitIntoRandomRangesOfApproximateLength(10, IntRange(0, l(data)))) stream.write(subByteArray(data, r)); } void writeAndReadInRandomRanges(byte[] data) ctex { int n = l(data), iRead = 0; for (r : splitIntoRandomRangesOfApproximateLength(10, IntRange(0, n))) { stream.write(subByteArray(data, r)); int readTo = random_incl(iRead, r.end); //printVars(+n, +r, +readTo, +iRead); for (; iRead < r.end; iRead++) assertEquals("Byte " + iRead, ubyteToInt(data[iRead]), stream.read()); // partially out of data if (iRead == r.end) assertEquals(-1, stream.read()); } // check reading rest of data for (; iRead < n; iRead++) assertEquals("Byte " + iRead, ubyteToInt(data[iRead]), stream.read()); } void checkRead(byte[] data) ctex { checkReadWithMark(data, -1); } void checkReadWithMark(byte[] data, int markPos) ctex { for i over data: { if (i == markPos) stream.mark(n); assertEquals("Byte " + i, ubyteToInt(data[i]), stream.read()); } assertEquals(-1, stream.read()); } void test2() ctex { stream = new ByteArraysPartialInputStream; writeAndReadInRandomRanges(randomBytes(n)); } void test1() ctex { stream = new ByteArraysPartialInputStream; data = randomBytes(n); writeInRandomRanges(data); int markPos = random(n); checkReadWithMark(data, markPos); print("Resetting to " + markPos); stream.reset(); checkRead(subByteArray(data, markPos)); print("Read OK"); } }