You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2015/07/28 23:04:30 UTC

svn commit: r1693162 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java

Author: hossman
Date: Tue Jul 28 21:04:29 2015
New Revision: 1693162

URL: http://svn.apache.org/r1693162
Log:
SOLR-7804: fix test bug that caused incorrect epsilon comparisons when expected value is negative.  also fix bug in "test the test" sanity checks of epsilon comparisons (merge r1693160)

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java?rev=1693162&r1=1693161&r2=1693162&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java Tue Jul 28 21:04:29 2015
@@ -733,7 +733,7 @@ public class TestCloudPivotFacet extends
     } else if (expected instanceof Float || expected instanceof Double) {
       // compute an epsilon relative to the size of the expected value
       double expect = ((Number)expected).doubleValue();
-      double epsilon = expect * 0.1E-7D;
+      double epsilon = Math.abs(expect * 0.1E-7D);
 
       assertEquals(msg, expect, ((Number)actual).doubleValue(), epsilon);
       
@@ -746,68 +746,82 @@ public class TestCloudPivotFacet extends
    * test the test
    */
   private void sanityCheckAssertNumerics() {
+    
     assertNumerics("Null?", null, null);
-    assertNumerics("big", 
+    assertNumerics("large a", 
                    new Double(2.3005390038169265E9), 
                    new Double(2.300539003816927E9));
+    assertNumerics("large b",
+                   new Double(1.2722582464444444E9),
+                   new Double(1.2722582464444442E9));
     assertNumerics("small", 
                    new Double(2.3005390038169265E-9), 
                    new Double(2.300539003816927E-9));
-    assertNumerics("small", 
-                   new Double(2.3005390038169265E-9), 
-                   new Double(2.300539003816927E-9));
+    
+    assertNumerics("large a negative", 
+                   new Double(-2.3005390038169265E9), 
+                   new Double(-2.300539003816927E9));
+    assertNumerics("large b negative",
+                   new Double(-1.2722582464444444E9),
+                   new Double(-1.2722582464444442E9));
+    assertNumerics("small negative", 
+                   new Double(-2.3005390038169265E-9), 
+                   new Double(-2.300539003816927E-9));
     
     assertNumerics("high long", Long.MAX_VALUE, Long.MAX_VALUE);
     assertNumerics("high int", Integer.MAX_VALUE, Integer.MAX_VALUE);
     assertNumerics("low long", Long.MIN_VALUE, Long.MIN_VALUE);
     assertNumerics("low int", Integer.MIN_VALUE, Integer.MIN_VALUE);
 
+    // NOTE: can't use 'fail' in these try blocks, because we are catching AssertionError
+    // (ie: the code we are expecting to 'fail' is an actual test assertion generator)
+    
     for (Object num : new Object[] { new Date(42), 42, 42L, 42.0F }) {
       try {
         assertNumerics("non-null", null, num);
-        fail("expected was null");
+        throw new RuntimeException("did not get assertion failure when expected was null");
       } catch (AssertionError e) {}
       
       try {
         assertNumerics("non-null", num, null);
-        fail("actual was null");
+        throw new RuntimeException("did not get assertion failure when actual was null");
       } catch (AssertionError e) {}
     }
   
     try {
       assertNumerics("non-number", "foo", 42);
-      fail("expected was non-number");
+      throw new RuntimeException("did not get assertion failure when expected was non-number");
     } catch (AssertionError e) {}
 
     try {
       assertNumerics("non-number", 42, "foo");
-      fail("actual was non-number");
+      throw new RuntimeException("did not get assertion failure when actual was non-number");
     } catch (AssertionError e) {}
   
     try {
       assertNumerics("diff", 
                      new Double(2.3005390038169265E9), 
                      new Double(2.267272520100462E9));
-      fail("big & diff");
+      throw new RuntimeException("did not get assertion failure when args are big & too diff");
     } catch (AssertionError e) {}
     try {
       assertNumerics("diff", 
                      new Double(2.3005390038169265E-9), 
                      new Double(2.267272520100462E-9));
-      fail("small & diff");
+      throw new RuntimeException("did not get assertion failure when args are small & too diff");
     } catch (AssertionError e) {}
   
     try {
       assertNumerics("diff long", Long.MAX_VALUE, Long.MAX_VALUE-1);
-      fail("diff long");
+      throw new RuntimeException("did not get assertion failure when args are diff longs");
     } catch (AssertionError e) {}
     try {
       assertNumerics("diff int", Integer.MAX_VALUE, Integer.MAX_VALUE-1);
-      fail("diff int");
+      throw new RuntimeException("did not get assertion failure when args are diff ints");
     } catch (AssertionError e) {}
     try {
       assertNumerics("diff date", new Date(42), new Date(43));
-      fail("diff date");
+      throw new RuntimeException("did not get assertion failure when args are diff dates");
     } catch (AssertionError e) {}
 
   }