how to test when correct output is "random"?

Steven Taschuk staschuk at telusplanet.net
Mon Apr 7 23:05:31 EDT 2003


Quoth Greg Ewing (using news.cis.dfn.de):
> 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.

Indeed.  I think I mentioned this idea under the heading "sanity
checks" later in my post.  I introduced permute() (which is not
the OP's example, note) to illustrate why I don't like the idea of
mocking the PRNG and testing for specific output.

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

Though note that such a test can produce false negatives.

  [...]
> 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.

Am I Mr. Tasch?  If so, whose post do you think you're quoting
above and, I infer, responding to?  I am puzzled.

-- 
Steven Taschuk                               staschuk at telusplanet.net
"[T]rue greatness is when your name is like ampere, watt, and fourier
 -- when it's spelled with a lower case letter."      -- R.W. Hamming





More information about the Python-list mailing list