how to test when correct output is "random"?

Greg Ewing (using news.cis.dfn.de) ckea25d02 at sneakemail.com
Sun Apr 6 22:57:40 EDT 2003


Steven Taschuk wrote:
> Consider two implementations of this function:
> 	def permute(seq):
> 		"""Returns a copy of seq, randomly permuted."""
> 		# ...

In that kind of situation, what you should probably
be checking is not that a particular permutation is
produced, but just that the output is *some* permutation
of the input.

You may also want to call it a few times and check
that it returns a different permutation each time.

That's probably good enough to pick up whether you've
broken anything.

If you're worried that the output might pass those
tests but still not be random enough, then you're
into statistical testing, as Mr. Tasch suggested.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list