@@ -105,7 +105,19 @@ private static class FakeScorerSupplier extends ScorerSupplier {
105
105
@ Override
106
106
public Scorer get (long leadCost ) throws IOException {
107
107
if (this .leadCost != null ) {
108
- assertEquals (this .toString (), this .leadCost .longValue (), leadCost );
108
+ if (this .leadCost < this .cost ) {
109
+ // If the expected lead cost is less than the cost, ie. another clause is leading
110
+ // iteration, then the exact lead cost must be provided.
111
+ assertEquals (
112
+ this .toString () + " actual leadCost=" + leadCost ,
113
+ this .leadCost .longValue (),
114
+ leadCost );
115
+ } else {
116
+ // Otherwise the lead cost may be provided as the cost of this very clause or as
117
+ // Long.MAX_VALUE (typically for bulk scorers), both signaling that this clause is leading
118
+ // iteration.
119
+ assertTrue (this .toString () + " actual leadCost=" + leadCost , leadCost >= this .leadCost );
120
+ }
109
121
}
110
122
return new FakeScorer (cost );
111
123
}
@@ -269,9 +281,10 @@ public void testDuelCost() throws Exception {
269
281
270
282
// test the tester...
271
283
public void testFakeScorerSupplier () {
272
- FakeScorerSupplier randomAccessSupplier = new FakeScorerSupplier (random ().nextInt (100 ), 30 );
284
+ FakeScorerSupplier randomAccessSupplier =
285
+ new FakeScorerSupplier (TestUtil .nextInt (random (), 31 , 100 ), 30 );
273
286
expectThrows (AssertionError .class , () -> randomAccessSupplier .get (70 ));
274
- FakeScorerSupplier sequentialSupplier = new FakeScorerSupplier (random ().nextInt (100 ), 70 );
287
+ FakeScorerSupplier sequentialSupplier = new FakeScorerSupplier (random ().nextInt (70 ), 70 );
275
288
expectThrows (AssertionError .class , () -> sequentialSupplier .get (30 ));
276
289
}
277
290
@@ -289,6 +302,9 @@ public void testConjunctionLeadCost() throws IOException {
289
302
new BooleanScorerSupplier (
290
303
new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
291
304
.get (Long .MAX_VALUE ); // triggers assertions as a side-effect
305
+ new BooleanScorerSupplier (
306
+ new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
307
+ .bulkScorer (); // triggers assertions as a side-effect
292
308
293
309
subs = new EnumMap <>(Occur .class );
294
310
for (Occur occur : Occur .values ()) {
@@ -315,6 +331,9 @@ public void testDisjunctionLeadCost() throws IOException {
315
331
new BooleanScorerSupplier (
316
332
new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
317
333
.get (100 ); // triggers assertions as a side-effect
334
+ new BooleanScorerSupplier (
335
+ new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
336
+ .bulkScorer (); // triggers assertions as a side-effect
318
337
319
338
subs .get (Occur .SHOULD ).clear ();
320
339
subs .get (Occur .SHOULD ).add (new FakeScorerSupplier (42 , 20 ));
@@ -338,6 +357,9 @@ public void testDisjunctionWithMinShouldMatchLeadCost() throws IOException {
338
357
new BooleanScorerSupplier (
339
358
new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 2 , 100 )
340
359
.get (100 ); // triggers assertions as a side-effect
360
+ new BooleanScorerSupplier (
361
+ new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 2 , 100 )
362
+ .bulkScorer (); // triggers assertions as a side-effect
341
363
342
364
subs = new EnumMap <>(Occur .class );
343
365
for (Occur occur : Occur .values ()) {
@@ -364,6 +386,9 @@ public void testDisjunctionWithMinShouldMatchLeadCost() throws IOException {
364
386
new BooleanScorerSupplier (
365
387
new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 2 , 100 )
366
388
.get (100 ); // triggers assertions as a side-effect
389
+ new BooleanScorerSupplier (
390
+ new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 2 , 100 )
391
+ .bulkScorer (); // triggers assertions as a side-effect
367
392
368
393
subs = new EnumMap <>(Occur .class );
369
394
for (Occur occur : Occur .values ()) {
@@ -377,6 +402,9 @@ public void testDisjunctionWithMinShouldMatchLeadCost() throws IOException {
377
402
new BooleanScorerSupplier (
378
403
new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 3 , 100 )
379
404
.get (100 ); // triggers assertions as a side-effect
405
+ new BooleanScorerSupplier (
406
+ new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 3 , 100 )
407
+ .bulkScorer (); // triggers assertions as a side-effect
380
408
}
381
409
382
410
public void testProhibitedLeadCost () throws IOException {
@@ -391,6 +419,9 @@ public void testProhibitedLeadCost() throws IOException {
391
419
new BooleanScorerSupplier (
392
420
new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
393
421
.get (100 ); // triggers assertions as a side-effect
422
+ new BooleanScorerSupplier (
423
+ new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
424
+ .bulkScorer (); // triggers assertions as a side-effect
394
425
395
426
subs .get (Occur .MUST ).clear ();
396
427
subs .get (Occur .MUST_NOT ).clear ();
@@ -399,6 +430,9 @@ public void testProhibitedLeadCost() throws IOException {
399
430
new BooleanScorerSupplier (
400
431
new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
401
432
.get (100 ); // triggers assertions as a side-effect
433
+ new BooleanScorerSupplier (
434
+ new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
435
+ .bulkScorer (); // triggers assertions as a side-effect
402
436
403
437
subs .get (Occur .MUST ).clear ();
404
438
subs .get (Occur .MUST_NOT ).clear ();
@@ -420,13 +454,17 @@ public void testMixedLeadCost() throws IOException {
420
454
subs .get (Occur .SHOULD ).add (new FakeScorerSupplier (30 , 42 ));
421
455
new BooleanScorerSupplier (new FakeWeight (), subs , ScoreMode .COMPLETE , 0 , 100 )
422
456
.get (100 ); // triggers assertions as a side-effect
457
+ new BooleanScorerSupplier (new FakeWeight (), subs , ScoreMode .COMPLETE , 0 , 100 )
458
+ .bulkScorer (); // triggers assertions as a side-effect
423
459
424
460
subs .get (Occur .MUST ).clear ();
425
461
subs .get (Occur .SHOULD ).clear ();
426
462
subs .get (Occur .MUST ).add (new FakeScorerSupplier (42 , 42 ));
427
463
subs .get (Occur .SHOULD ).add (new FakeScorerSupplier (80 , 42 ));
428
464
new BooleanScorerSupplier (new FakeWeight (), subs , ScoreMode .COMPLETE , 0 , 100 )
429
465
.get (100 ); // triggers assertions as a side-effect
466
+ new BooleanScorerSupplier (new FakeWeight (), subs , ScoreMode .COMPLETE , 0 , 100 )
467
+ .bulkScorer (); // triggers assertions as a side-effect
430
468
431
469
subs .get (Occur .MUST ).clear ();
432
470
subs .get (Occur .SHOULD ).clear ();
0 commit comments