java - Assert Equals (double, double, delta) Issue -


i trying create assert equals (double, double, epsilon) method. created , reason when run tester, method failing.

public static void assertequals(double expect, double actual, double epsilon){     totalassertmethods ++;     double difference = (math.abs(expect - actual));     if (difference <= epsilon){      } else {         totalassertmethodsfailures ++;         throwable throwable = new throwable("error: expected x +/-e, found y");         throwable.printstacktrace();     } } 

i think problem is, difference between expect , actual in test different epsilon approx 0.000001. know how go fixing this?

try round off values precision:

double difference = math.round(math.abs(expect - actual) * 100000d) / 100000d; 

do same thing epsilon also.

double finalepsilon = math.round(epsilon * 100000d) / 100000d; 

Comments