Re: [Python-Dev] Optional delta argument for assertAlmostEqual

2010-03-28 Thread geremy condra
On Fri, Mar 26, 2010 at 8:59 PM, Michael Foord wrote: > Hello all, > > A user has suggested an optional argument to > unittest.TestCase.assertAlmostEqual for specifying a maximum difference > between the expected and actual values, instead of using rounding. > > This sounds great to me as the defa

Re: [Python-Dev] Optional delta argument for assertAlmostEqual

2010-03-28 Thread Charles McCreary
A good summary on floating point comparison algorithms can be found at http://www.boost.org/doc/libs/1_34_0/libs/test/doc/components/test_tools/floating_point_comparison.html I, too, redefine almostEquals so that the comparison is more robust +1 On Sun, Mar 28, 2010 at 2:06 AM, Steven D'Aprano

Re: [Python-Dev] Optional delta argument for assertAlmostEqual

2010-03-28 Thread Steven D'Aprano
On Sun, 28 Mar 2010 02:54:19 pm Charles McCreary wrote: > Perhaps not just absolute but relative tolerance, e.g.: > > def isclose(x, y, rtol=1.e-5, atol=1.e-8): > return abs(x-y) <= atol + rtol * abs(y) I'm not sure why you add the tolerances like that. Surely a more appropriate approach is t

Re: [Python-Dev] Optional delta argument for assertAlmostEqual

2010-03-27 Thread Charles McCreary
Perhaps not just absolute but relative tolerance, e.g.: def isclose(x, y, rtol=1.e-5, atol=1.e-8): return abs(x-y) <= atol + rtol * abs(y) On Fri, Mar 26, 2010 at 7:59 PM, Michael Foord wrote: > Hello all, > > A user has suggested an optional argument to > unittest.TestCase.assertAlmostEqual

Re: [Python-Dev] Optional delta argument for assertAlmostEqual

2010-03-27 Thread Gregory P. Smith
On Fri, Mar 26, 2010 at 5:59 PM, Michael Foord wrote: > Hello all, > > A user has suggested an optional argument to > unittest.TestCase.assertAlmostEqual for specifying a maximum difference > between the expected and actual values, instead of using rounding. > > This sounds great to me as the defa

Re: [Python-Dev] Optional delta argument for assertAlmostEqual

2010-03-27 Thread Mark Dickinson
On Sat, Mar 27, 2010 at 12:59 AM, Michael Foord wrote: > Hello all, > > A user has suggested an optional argument to > unittest.TestCase.assertAlmostEqual for specifying a maximum difference > between the expected and actual values, instead of using rounding. +1. Mark ___

[Python-Dev] Optional delta argument for assertAlmostEqual

2010-03-26 Thread Michael Foord
Hello all, A user has suggested an optional argument to unittest.TestCase.assertAlmostEqual for specifying a maximum difference between the expected and actual values, instead of using rounding. This sounds great to me as the default implementation of assertAlmostEqual has *never* been usefu