Java Assert Equal assertApproxEquals(double a, double b, double relative, double absolute)

Here you can find the source of assertApproxEquals(double a, double b, double relative, double absolute)

Description

assert Approx Equals

License

Open Source License

Declaration

public static void assertApproxEquals(double a, double b, double relative, double absolute) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void assertApproxEquals(double a, double b, double relative, double absolute, String message) {
        double diff = Math.abs(a - b);
        if (absolute >= 0 && diff <= absolute)
            return;
        double rel = diff / Math.max(a, b);
        if (relative >= 0 && rel <= relative)
            return;
        throw new AssertionError("two numbers are not equal enough: " + a + "!= " + b + ", rel=" + rel + ">"
                + relative + ", abs=" + diff + ">" + absolute + (message != null ? " (" + message + ")" : ""));
    }//  ww w .j  a v  a2s  .com

    public static void assertApproxEquals(double a, double b, double relative, double absolute) {
        assertApproxEquals(a, b, relative, absolute, null);
    }
}

Related

  1. assertAboveEqual(final double number, final double value)
  2. assertArrayEquals(double[] p1, double[] p2, double eps)
  3. assertArrayLengthEqual(Object[] array, String name, Object[] array1, String name1)
  4. assertCharacterArraysEqual(char[] first, char[] second)
  5. assertDatesEqual(Calendar first, Calendar second)