elf elf - 1 year ago 153
Java Question

Meaning of epsilon argument of assertEquals for double values

I have a question about junit assertEquals to test double values. Reading API doc I can see:

public static void assertEquals(double expected, double actual)

Deprecated. Use assertEquals(double
expected, double actual, double
epsilon) instead

What does epsilon value mean? (Epsilon is a letter in the Greek alphabet, right?).

Can Someone explain to me how to use it?

Answer Source

Epsilon is the value that the 2 numbers can be off by. So it will assert to true as long as Math.abs(expected - actual) < epsilon

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download