As a direct consequence of the IEEE 754 format for floating point numbers, it is impossible to achieve 100% accuracy and precision in testing floating point values. A pragmatic heuristic to follow involves factoring in the inputs to the method and padding the expected return value with a suitable error threshold.
For example, 0.1 + 0.2 is not equal to 0.3 in this format. Keep this in mind while designing unit tests and choose an appropriate error tolerance range. Another good practice for mathematical methods is to test them against similar existing implementations
As a direct consequence of the IEEE 754 format for floating point numbers, it is impossible to achieve 100% accuracy and precision in testing floating point values. A pragmatic heuristic to follow involves factoring in the inputs to the method and padding the expected return value with a suitable error threshold.
For example, 0.1 + 0.2 is not equal to 0.3 in this format. Keep this in mind while designing unit tests and choose an appropriate error tolerance range. Another good practice for mathematical methods is to test them against similar existing implementations