@@ -105,7 +105,19 @@ private static class FakeScorerSupplier extends ScorerSupplier {
105105 @ Override
106106 public Scorer get (long leadCost ) throws IOException {
107107 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+ }
109121 }
110122 return new FakeScorer (cost );
111123 }
@@ -269,9 +281,10 @@ public void testDuelCost() throws Exception {
269281
270282 // test the tester...
271283 public void testFakeScorerSupplier () {
272- FakeScorerSupplier randomAccessSupplier = new FakeScorerSupplier (random ().nextInt (100 ), 30 );
284+ FakeScorerSupplier randomAccessSupplier =
285+ new FakeScorerSupplier (TestUtil .nextInt (random (), 31 , 100 ), 30 );
273286 expectThrows (AssertionError .class , () -> randomAccessSupplier .get (70 ));
274- FakeScorerSupplier sequentialSupplier = new FakeScorerSupplier (random ().nextInt (100 ), 70 );
287+ FakeScorerSupplier sequentialSupplier = new FakeScorerSupplier (random ().nextInt (70 ), 70 );
275288 expectThrows (AssertionError .class , () -> sequentialSupplier .get (30 ));
276289 }
277290
@@ -289,6 +302,9 @@ public void testConjunctionLeadCost() throws IOException {
289302 new BooleanScorerSupplier (
290303 new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
291304 .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
292308
293309 subs = new EnumMap <>(Occur .class );
294310 for (Occur occur : Occur .values ()) {
@@ -315,6 +331,9 @@ public void testDisjunctionLeadCost() throws IOException {
315331 new BooleanScorerSupplier (
316332 new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
317333 .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
318337
319338 subs .get (Occur .SHOULD ).clear ();
320339 subs .get (Occur .SHOULD ).add (new FakeScorerSupplier (42 , 20 ));
@@ -338,6 +357,9 @@ public void testDisjunctionWithMinShouldMatchLeadCost() throws IOException {
338357 new BooleanScorerSupplier (
339358 new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 2 , 100 )
340359 .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
341363
342364 subs = new EnumMap <>(Occur .class );
343365 for (Occur occur : Occur .values ()) {
@@ -364,6 +386,9 @@ public void testDisjunctionWithMinShouldMatchLeadCost() throws IOException {
364386 new BooleanScorerSupplier (
365387 new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 2 , 100 )
366388 .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
367392
368393 subs = new EnumMap <>(Occur .class );
369394 for (Occur occur : Occur .values ()) {
@@ -377,6 +402,9 @@ public void testDisjunctionWithMinShouldMatchLeadCost() throws IOException {
377402 new BooleanScorerSupplier (
378403 new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 3 , 100 )
379404 .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
380408 }
381409
382410 public void testProhibitedLeadCost () throws IOException {
@@ -391,6 +419,9 @@ public void testProhibitedLeadCost() throws IOException {
391419 new BooleanScorerSupplier (
392420 new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
393421 .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
394425
395426 subs .get (Occur .MUST ).clear ();
396427 subs .get (Occur .MUST_NOT ).clear ();
@@ -399,6 +430,9 @@ public void testProhibitedLeadCost() throws IOException {
399430 new BooleanScorerSupplier (
400431 new FakeWeight (), subs , RandomPicks .randomFrom (random (), ScoreMode .values ()), 0 , 100 )
401432 .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
402436
403437 subs .get (Occur .MUST ).clear ();
404438 subs .get (Occur .MUST_NOT ).clear ();
@@ -420,13 +454,17 @@ public void testMixedLeadCost() throws IOException {
420454 subs .get (Occur .SHOULD ).add (new FakeScorerSupplier (30 , 42 ));
421455 new BooleanScorerSupplier (new FakeWeight (), subs , ScoreMode .COMPLETE , 0 , 100 )
422456 .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
423459
424460 subs .get (Occur .MUST ).clear ();
425461 subs .get (Occur .SHOULD ).clear ();
426462 subs .get (Occur .MUST ).add (new FakeScorerSupplier (42 , 42 ));
427463 subs .get (Occur .SHOULD ).add (new FakeScorerSupplier (80 , 42 ));
428464 new BooleanScorerSupplier (new FakeWeight (), subs , ScoreMode .COMPLETE , 0 , 100 )
429465 .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
430468
431469 subs .get (Occur .MUST ).clear ();
432470 subs .get (Occur .SHOULD ).clear ();
0 commit comments