Apache Solr open-source search software
SOLR-3024: Fixed JSONTestUtil.matchObj to respect delta param
Chris M. Hostetteref4e44f30b7d
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 026c30a2761..c5b32497a9a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -448,6 +448,9 @@ Bug Fixes* SOLR-2956: Fixed inconsistencies in the flags (and flag key) reported bythe LukeRequestHandler (hossman)++* SOLR-3024: Fixed JSONTestUtil.matchObj, in previous releases it was not+ respecting the 'delta' arg (David Smiley via hossman)Other Changes----------------------diff --git a/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java b/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.javaindex 1900e13c8c6..fcce6471c52 100644--- a/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java+++ b/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java@@ -78,7 +78,7 @@ public class JSONTestUtil {public static String match(String path, String input, String expected, double delta) throws Exception {Object inputObj = ObjectBuilder.fromJSON(input);Object expectObj = ObjectBuilder.fromJSON(expected);- return matchObj(path, inputObj, expectObj);+ return matchObj(path, inputObj, expectObj, delta);}/**@@ -88,7 +88,7 @@ public class JSONTestUtil {* @param delta tollerance allowed in comparing float/double values*/public static String matchObj(String path, Object input, Object expected, double delta) throws Exception {- CollectionTester tester = new CollectionTester(input);+ CollectionTester tester = new CollectionTester(input,delta);boolean reversed = path.startsWith("!");String positivePath = reversed ? path.substring(1) : path;if (!tester.seek(positivePath) ^ reversed) {@@ -181,19 +181,16 @@ class CollectionTester {// make an exception for some numericsif ((expected instanceof Integer && val instanceof Long || expected instanceof Long && val instanceof Integer)- && ((Number)expected).longValue() == ((Number)val).longValue())- {+ && ((Number)expected).longValue() == ((Number)val).longValue()) {return true;- } else if ((expected instanceof Float && val instanceof Double || expected instanceof Double && val instanceof Float)) {+ } else if ((expected instanceof Double || expected instanceof Float) && (val instanceof Double || val instanceof Float)) {double a = ((Number)expected).doubleValue();double b = ((Number)val).doubleValue();if (Double.compare(a,b) == 0) return true;if (Math.abs(a-b) < delta) return true;- return false;- } else {- setErr("mismatch: '" + expected + "'!='" + val + "'");- return false;}+ setErr("mismatch: '" + expected + "'!='" + val + "'");+ return false;}// setErr("unknown expected type " + expected.getClass().getName());