lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1066865 - in /lucene/dev/branches/branch_3x: ./ lucene/ solr/ solr/src/test/org/apache/solr/JSONTestUtil.java
Date Thu, 03 Feb 2011 16:55:42 GMT
Author: yonik
Date: Thu Feb  3 16:55:42 2011
New Revision: 1066865

URL: http://svn.apache.org/viewvc?rev=1066865&view=rev
Log:
tests: fix comparing some json numerics

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/JSONTestUtil.java

Modified: lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/JSONTestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/JSONTestUtil.java?rev=1066865&r1=1066864&r2=1066865&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/JSONTestUtil.java (original)
+++ lucene/dev/branches/branch_3x/solr/src/test/org/apache/solr/JSONTestUtil.java Thu Feb
 3 16:55:42 2011
@@ -129,8 +129,22 @@ class CollectionTester {
 
     // generic fallback
     if (!expected.equals(val)) {
-      setErr("mismatch: '" + expected + "'!='" + val + "'");
-      return false;
+
+      // make an exception for some numerics
+      if ((expected instanceof Integer && val instanceof Long || expected instanceof
Long && val instanceof Integer)
+          && ((Number)expected).longValue() == ((Number)val).longValue())
+      {
+        return true;
+      } else if ((expected instanceof Float && val instanceof Double || expected
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) < 1e-5) return true;
+        return false;
+      } else {
+        setErr("mismatch: '" + expected + "'!='" + val + "'");
+        return false;
+      }
     }
 
     // setErr("unknown expected type " + expected.getClass().getName());



Mime
View raw message