Skip to content

Commit b9fc841

Browse files
committed
speed up nth overflow test
1 parent a4f19aa commit b9fc841

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

src/test/java/io/github/jhspetersson/packrat/NthTest.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,24 @@ public void nthWithExactlyNElementsTest() {
5555

5656
@Test
5757
public void nthShouldKeepCadenceBeyondMaxIntElements() {
58-
var gatherer = new NthGatherer<Integer>(1_000_000);
59-
var state = gatherer.initializer().get();
58+
var n = 5;
59+
var gatherer = new NthGatherer<Integer>(n);
6060
var integrator = gatherer.integrator();
6161

62-
var lastPushPosition = new long[] { -1 };
63-
var currentPosition = new long[1];
64-
var badGap = new long[] { -1 };
65-
62+
// simulate having already consumed 2^31 - 3 elements
63+
var state = new long[] { Integer.MAX_VALUE - 2 };
64+
var taken = new java.util.ArrayList<Long>();
6665
Gatherer.Downstream<Integer> downstream = _ -> {
67-
if (lastPushPosition[0] >= 0 && currentPosition[0] - lastPushPosition[0] != 1_000_000) {
68-
badGap[0] = currentPosition[0] - lastPushPosition[0];
69-
}
70-
lastPushPosition[0] = currentPosition[0];
66+
taken.add(state[0]);
7167
return true;
7268
};
7369

74-
var total = (1L << 31) + 2_000_000L;
75-
for (var i = 0L; i < total; i++) {
76-
currentPosition[0] = i;
70+
for (var i = 0; i < 10; i++) {
7771
integrator.integrate(state, 0, downstream);
7872
}
7973

80-
assertEquals(-1, badGap[0], "cadence broke, gap of " + badGap[0]);
74+
// taken positions must stay exact multiples of n across the int boundary
75+
assertEquals(List.of(2_147_483_650L, 2_147_483_655L), taken);
8176
}
8277

8378
@Test

0 commit comments

Comments
 (0)