elf elf - 2 months ago 10
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?


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