[Tutor] Please review my code - a simple iterator thingy to make round-robin pairings

Pekka Karjalainen pekka.henrik.karjalainen at googlemail.com
Tue Dec 13 08:32:45 CET 2005


Thank you for the response, Danny!

On 12/12/05, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
>
> One thing you can add is unit tests to see that your program is doing what
> you expect.  There's a great example of how unit tests work in Mark
> Pilgrim's "Dive into Python":
>
>     http://diveintopython.org/unit_testing/index.html
>
> and the things they talk about there can be applied to your program.
> Have you played with 'unittest' before?

It's time I started. I'll look there first and work on it.

> We might want to interchange the list copying with the code that ensures
> len(players) is even. Otherwise, the caller can see mutation of their
> input list, which goes contrary to doing the list copy in the first place.
> *grin*

That's a very good point. Noted.

> Otherwise, the main thing I'd recommend is to back the algorithm with unit
> tests;  the implementation has some subtle details (like interchanging
> colors) that has enough special cases to make me a little hesitant.  Unit
> testing would help us to have more confidence in those special cases.
> Otherwise, looks good!

I have an informal, but to my mind solid, proof for it working
elsewhere. But being aware of what even Don Knuth thinks of
correctness proofs wrt to programs ("I've only proved it correct..."),
I'm not going to disregard testing. Time to think of good test cases
now and do some reading. Thanks for the heads up.

(Also, I should check how to handle empty lists.)

Pekka


More information about the Tutor mailing list