[TIP] doctest and floats
raphael.marvie at lifl.fr
Mon Mar 10 02:10:03 PDT 2008
I use comparisons to define expectations
>>> 0.1 == f()
I don't know if this is the one way, but I used it for scientific
Tim Head wrote:
> if you want to test a function that returns a float, what is the "one
> way" to write that down in a doctest?
> def foo(n):
> >>> foo(0.4)
> >>> foo(0.1)
> return n
> this will fail on the second one because 0.1 is one of these numbers
> that can be represented completely in binary.
> It feels wrong to write
> does not work either.
> Does anyone of you clever people have some experience with how to do
> this properly?
Raphael Marvie, PhD http://www.lifl.fr/~marvie/
Maître de Conférences / Associate Professor @ LIFL -- USTL
Directeur du Master Informatique Professionnel spécialité IAGL
Head of Master's in Software Engineering +33 3 28 77 85 83
More information about the testing-in-python