SimplePrograms challenge

Steve Howell showell30 at yahoo.com
Wed Jun 20 09:26:14 EDT 2007


--- Pete Forman <pete.forman at westerngeco.com> wrote:

> Steve Howell <showell30 at yahoo.com> writes:
> 
> >> 2) assert is not the simplest example of doctest.
> 
> >> The style should be
> >> 
> >>     >>> add_money([0.13, 0.02])
> >>     0.15
> >>     >>> add_money([100.01, 99.99])
> >>     200.0
> >>     >>> add_money([0, -13.00, 13.00])
> >>     0.0
> >> 
> >
>  > That's not clear cut to me.  I think vertical
>  > conciseness has an advantage for readability, as
> it
>  > means you get to keep more "real" code on the
> screen.
> 
> What I meant was that doctest should be "type this
> into the
> interpreter and you should see that".  A doctest is
> not a unit test,
> though it may form a subset of the tests.  There
> should only be enough
> doctests to enclue a human reader.  Comprehensive
> testing should use a
> larger framework.  Doctests in separate files can do
> this but I would
> use py.test, or alternatives like nose or Testoob.
> 
>     >>> 2 + 2
>     4
> 
> "assert 2 + 2 == 4" is a concise way of writing a
> unit test but it is
> not the best way to use doctest IMHO.
> 
> >> 3) which fails :-(  So both the unittest and
> doctest
> >> examples ought to
> >>    be redone to emphasize what they are doing
> >> without getting bogged
> >>    down by issues of floating point
> representations.
> >> 
> >
>  > I was the one who originally posted the floating
> point
>  > example (with yet another style of unit testing,
> BTW),
>  > and I agree that the subtleties of floating point
> do
>  > kind of cloud the issue.  I welcome a better
> example. 
>  > What I didn't realize is that there's an actual
> error.
>  >  Are you saying the program fails?  On which
> test?
> 
> Python 2.5.1 on XP:
> 
> Failed example:
>     add_money([0.13, 0.02])
> Expected:
>     0.15
> Got:
>     0.14999999999999999
> 
> 

Ok, you make a lot of good points.  I was the original
author of the page, so I'll make a few points.

  1) Your attention to detail is greatly appreciated. 
At the very least, I don't want the examples to be
broken.  I tested the above on Unix 2.5, and they
worked, but it was obviously just luck, as the
implementation is clearly broken.  (Actually, it's not
so much the implementation--it's the interface, which
should just return pennies.)

  2) Both the unittest and doctest examples are
probably broken.

  3) I'd like for unittest and doctest example to show
up somewhere on the page, but perhaps they merit
longer examples.

  4) I don't use doctest myself.  It never hit my
sweet spot, mostly because I prefer external unit
tests.  So I'm not the best person to judge the most
idiomatic way to write them.

  5) My biggest goal for the page is that examples are
simple and mostly uncontroversial.

  6) It was pointed out when I originally wrote this
example that the solution to money rounding is, of
course, to use a Decimal data type.

  7) Feel free to change the page as you see fit,
although thanks for discussing it here first.



 
____________________________________________________________________________________
It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/



More information about the Python-list mailing list