예제 #1
0
 public void testFuzzyEqualsOneNaN() {
   for (double a : DOUBLE_CANDIDATES_EXCEPT_NAN) {
     for (double tolerance : TOLERANCE_CANDIDATES) {
       assertFalse(DoubleMath.fuzzyEquals(a, Double.NaN, tolerance));
       assertFalse(DoubleMath.fuzzyEquals(Double.NaN, a, tolerance));
     }
   }
 }
예제 #2
0
 public void testFuzzyInfiniteVersusInfiniteWithFiniteTolerance() {
   for (double inf : INFINITIES) {
     for (double tolerance : FINITE_TOLERANCE_CANDIDATES) {
       assertTrue(DoubleMath.fuzzyEquals(inf, inf, tolerance));
       assertFalse(DoubleMath.fuzzyEquals(inf, -inf, tolerance));
     }
   }
 }
예제 #3
0
 public void testFuzzyEqualsInfiniteTolerance() {
   for (double a : DOUBLE_CANDIDATES_EXCEPT_NAN) {
     for (double b : DOUBLE_CANDIDATES_EXCEPT_NAN) {
       assertTrue(DoubleMath.fuzzyEquals(a, b, Double.POSITIVE_INFINITY));
     }
   }
 }
예제 #4
0
 public void testFuzzyEqualsFinite() {
   for (double a : FINITE_DOUBLE_CANDIDATES) {
     for (double b : FINITE_DOUBLE_CANDIDATES) {
       for (double tolerance : FINITE_TOLERANCE_CANDIDATES) {
         assertEquals(Math.abs(a - b) <= tolerance, DoubleMath.fuzzyEquals(a, b, tolerance));
       }
     }
   }
 }
예제 #5
0
 public void testFuzzyEqualsBadTolerance() {
   for (double tolerance : BAD_TOLERANCE_CANDIDATES) {
     try {
       DoubleMath.fuzzyEquals(1, 2, tolerance);
       fail("Expected IllegalArgumentException");
     } catch (IllegalArgumentException expected) {
       // success
     }
   }
 }
예제 #6
0
 public void testFuzzyCompare() {
   for (double a : ALL_DOUBLE_CANDIDATES) {
     for (double b : ALL_DOUBLE_CANDIDATES) {
       for (double tolerance : TOLERANCE_CANDIDATES) {
         int expected = DoubleMath.fuzzyEquals(a, b, tolerance) ? 0 : Double.compare(a, b);
         int actual = DoubleMath.fuzzyCompare(a, b, tolerance);
         assertEquals(Integer.signum(expected), Integer.signum(actual));
       }
     }
   }
 }
예제 #7
0
 public void testFuzzyEqualsZeroTolerance() {
   // make sure we test -0 tolerance
   for (double zero : Doubles.asList(0.0, -0.0)) {
     for (double a : ALL_DOUBLE_CANDIDATES) {
       for (double b : ALL_DOUBLE_CANDIDATES) {
         assertEquals(
             a == b || (Double.isNaN(a) && Double.isNaN(b)), DoubleMath.fuzzyEquals(a, b, zero));
       }
     }
   }
 }
예제 #8
0
 public void testFuzzyEqualsTwoNaNs() {
   for (double tolerance : TOLERANCE_CANDIDATES) {
     assertTrue(DoubleMath.fuzzyEquals(Double.NaN, Double.NaN, tolerance));
   }
 }