From 76fd471b54abb40063bbbcd0820a67ebeab6278d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 4 Oct 2011 14:52:32 +0000 Subject: [PATCH] LUCENE-3478: ensure the epsilon is always at least a tiny size for crazy small scores git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1178819 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/search/CheckHits.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lucene/src/test-framework/org/apache/lucene/search/CheckHits.java b/lucene/src/test-framework/org/apache/lucene/search/CheckHits.java index dbf6efa910d..3aab5faf06e 100644 --- a/lucene/src/test-framework/org/apache/lucene/search/CheckHits.java +++ b/lucene/src/test-framework/org/apache/lucene/search/CheckHits.java @@ -37,6 +37,14 @@ public class CheckHits { * this allows for a small amount of relative variation */ public static float EXPLAIN_SCORE_TOLERANCE_DELTA = 0.001f; + + /** + * In general we use a relative epsilon, but some tests do crazy things + * like boost documents with 0, creating tiny tiny scores where the + * relative difference is large but the absolute difference is tiny. + * we ensure the the epsilon is always at least this big. + */ + public static float EXPLAIN_SCORE_TOLERANCE_MINIMUM = 1e-6f; /** * Tests that all documents up to maxDoc which are *not* in the @@ -306,7 +314,7 @@ public class CheckHits { } private static float explainToleranceDelta(float f1, float f2) { - return Math.max(Math.abs(f1), Math.abs(f2)) * EXPLAIN_SCORE_TOLERANCE_DELTA; + return Math.max(EXPLAIN_SCORE_TOLERANCE_MINIMUM, Math.max(Math.abs(f1), Math.abs(f2)) * EXPLAIN_SCORE_TOLERANCE_DELTA); } /**