[Pyrex] Question, plus suggestions for improvement?

Bill Mill bill.mill at gmail.com
Wed Aug 2 12:36:25 UTC 2006


On 8/2/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Bill Mill wrote:
>
> > I thought, on inspection, that x, y, and z would need to be declared
> > as objects to accept arbitrary values from a list. However, if I pass
> > in a list of strings or floats, everything works just fine.
>
> I'm betting you never tested it with a list of
> more than 3 items.
>
> You seem to have some special case code in there
> for dealing with the first 3 items, which doesn't
> use the x, y, z variables.
>
> With a list of length 4, an exception occurs as
> expected:
>
> ['a', 'b', 'c', 'd']
> ['a', 'b', 'd', 'c']
> ['a', 'c', 'b', 'd']
> ['a', 'c', 'd', 'b']
> ['a', 'd', 'b', 'c']
> ['a', 'd', 'c', 'b']
> Traceback (most recent call last):
>    File "test.py", line 6, in ?
>      for p in Permute2(["a","b","c","d"]):
>    File "perm.pyx", line 32, in perm.Permute2.__next__
>      y = self.lst[j]
> TypeError: an integer is required
>
> The moral: Make sure your tests cover all the code
> paths!

Doh! Great catch, and one I should have made.

(The problem with having lots of permutation algorithm tests is that
they take *forever*, but clearly I need to be a little more patient
and make sure I hit all code paths.)

I'm glad I read it right, at least.

Many Thanks,
Bill Mill
bill.mill at gmail.com



More information about the Pyrex mailing list