Exhaustive Unit Testing

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Nov 30 06:03:08 CET 2008

On Sun, 30 Nov 2008 03:42:50 +0000, Steven D'Aprano wrote:

> def lcm(a, b):
>     return a/gcd(a, b)*b
> (By the way: there's a subtle bug in lcm() that will hit you in Python 
3. Can you spot it?

Er, ignore this. Division in Python 3 only returns a float if the 
remainder is non-zero, and when dividing by the gcd the remainder should 
always be zero.

> Here's a hint: your unit tests should also assert that 
> the result of lcm is always an int.)

Still good advise.


More information about the Python-list mailing list