
On 24 January 2015 at 07:30, Nathaniel Smith <njs@pobox.com> wrote:
On Fri, Jan 23, 2015 at 12:40 AM, Chris Barker <chris.barker@noaa.gov> wrote:
Existing Implementations ------------------------
The standard library includes the ``unittest.TestCase.assertAlmostEqual`` method, but it:
* Is buried in the unittest.TestCase class
* Is an assertion, so you can't use it as a general test (easily)
* Uses number of decimal digits or an absolute delta, which are particular use cases that don't provide a general relative error.
I might phrase this a bit more strongly -- assertAlmostEqual is confusing and broken-by-default for common cases like comparing two small values, or comparing two large values.
I would personally find the PEP more persuasive if it was framed in terms of providing an improved definition of assertAlmostEqual that better handles the limitations of binary floating point dynamic ranges. The fact that unittest.assertAlmostEqual is in the standard library implies that any improvement to it must also be in the standard library, and moving the definition of near equality that unittest uses out to the math module so it is reusable in other contexts makes sense to me, especially if it means being able to share the definition between unittest and the statistics module. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia