Fix assert to check the deviation rather than the absolute difference.

Deviation should be less or equal to 0.01 ~ 1% after the cast.
This commit is contained in:
Simon Willnauer 2013-08-13 17:38:24 +02:00
parent ba13930b32
commit 8774c46cc5
2 changed files with 6 additions and 3 deletions

View File

@ -200,8 +200,13 @@ public class FunctionScoreQuery extends Query {
}
public static float toFloat(double input) {
assert Double.compare(((float) input), input) == 0 || (Math.abs(((float) input) - input) <= 0.001) : "input " + input + " out of float scope for function score";
assert deviation(input) <= 0.001 : "input " + input + " out of float scope for function score deviation: " + deviation(input);
return (float) input;
}
private static double deviation(double input) { // only with assert!
float floatVersion = (float)input;
return Double.compare(floatVersion, input) == 0 || input == 0.0d ? 0 : 1.d-(floatVersion) / input;
}
}

View File

@ -21,7 +21,6 @@ package org.elasticsearch.test.integration.search.functionscore;
import org.apache.lucene.search.ComplexExplanation;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
@ -62,7 +61,6 @@ public class FunctionScorePluginTests extends AbstractNodesTests {
}
@Test
@LuceneTestCase.AwaitsFix(bugUrl = "britta to look into it, it creates a double value that fails the toFloat assertion")
public void testPlugin() throws Exception {
ImmutableSettings.Builder settings = settingsBuilder().put("plugin.types", CustomDistanceScorePlugin.class.getName());
startNode("server1", settings);