[Tutor] unit testing
Bruce Sass
bsass@freenet.edmonton.ab.ca
Fri, 14 Sep 2001 14:04:19 -0600 (MDT)
On Fri, 14 Sep 2001, Sean 'Shaleh' Perry wrote:
<...>
> i.e. pass it a value you know the answer for. Now this is a silly case you
> would really like to make sure they got things like every 400 years or not when
> the moon is blue. In other words pick places where the algorithm could have
> been broken. This is not easy for beginners and whether they use pyunit or not
> it will still be a task for them to learn. What my profs told us was pass
> values to test every if, else and while.
To expand on what Sean wrote...
What you want to test are the so-called `boundry conditions', where
the behaviour of the algorithm changes. i.e., if you have a block of
code that accepts a range of values, say min to max, you want to test
it at: min-1, min, max, and max +1.
> In a language like python what I typically do is write my functions then start
> the interpreter and load my code as a module and run the functions dynamically.
> This has spoiled me to no end and makes writing C painful now.
ditto... I think this is where the doctest module comes into play.
- Bruce