elf elf - 4 months ago 17
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:


@Deprecated
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

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