[Tutor] unittest with random population data

Cameron Simpson cs at zip.com.au
Wed Jun 3 10:06:21 CEST 2015


[ I've taken this discussion back to the tutor list. - Cameron ]

On 01Jun2015 18:14, Sydney Shall <s.shall at virginmedia.com> wrote:
>On 31/05/2015 03:00, Cameron Simpson wrote:
>>You say that your results are "all rather close, consistent with the sigma
>>value I have chosen for the spread of my population". I would advocate
>>making some "contraint" tests that verify this property for _any_ input
>>data set.
>>
>>Then you can run with random and _changing_ input data sets to verify
>>that your code produces the expected _kind_ of results with many data sets.
[...]
>>range class which stores contiguous ranges efficiently (a sequence of
>>(low,high) pairs). It has a few add/remove operations which are meant to
>>maintain that sequence on ordered minimal form. cutting and merging
>>adjacent ranges is very easy to get wrong, very sensitive to off-by-one
>>logic errors.
>>
>>So my tests for this class include some random tests which do random
>>unpredictable add/remove operations, and run a consistency check on the
>>object after each operation. This gives me good odds of exercising some
>>tricky sequence which I have not considered explicitly myself.
>>
>>You can see the test suite here:
>>  https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/range_tests.py
>
>I have studied the material you indicated and it has been most
>helpful. I think that I have understood the principle involved, but I
>have had some problem implementing it.
>
>The range tests are mostly clear to me but there is one aspect I 
>cannot follow.
>You use in this suite imports from Range, including Range, overlap, 
>spans and Span.
>Are these programs that you have written? If so, are they specific to 
>your set up or are they generic? If so, is it possible to obtain these 
>programs?

The "cs.range" is a module of my own. As you might imagine, cs.range_tests has 
the entire purpose of testing cs.range. cs.range is here:

  https://bitbucket.org/cameron_simpson/css/src/tip/lib/python/cs/range.py

Feel free. Since it in turn has some dependencies the easiest way to get it is 
to use "pip" to install it, as pip will also fetch and insteall its 
dependencies. But if you just want something to read, fetch and enjoy.

>I have established a very primitive test suite based on your cs.range >notions 
and it works fine, but it would be better, I am sure, to do it >properly.

There are many other people whose test writing ability surpasses mine.  But 
you're welcome to learn anything you can from mine, and to ask questions.  

>Finally, I have one comment for the respected Moderator, if he is not 
>out on a walk in the highlands in this cold  and wet weather.
>
>I have taken the liberty of raising my problem here rather than 
>elsewhere, because I have observed that the biological and bio-medical 
>community, who always come late to new notions, is now rapidly 
>discovering  python. A great deal of work in these fields involve 
>either stochastic simulations or statistical problems of analysis. The 
>latter are more or less straight-forward, but the simulations are not.

You might ask a separate question on the python-list at python.org about 
simulations. It has a wider audience than the tutor list and may well include 
people doing simulation work, or who know where to look.

>Thanks for all the help. You people are a model of how we could 
>perhaps civilize humanity.

Nah. We might all be striving to be a model of how humanity might be when 
civilised though...

Cheers,
Cameron Simpson <cs at zip.com.au>

You my man are a danger to society and should be taken out of society for all
our sakes. As to what is done to you once removed I couldn't care less.
        - Roy G. Culley, Unix Systems Administrator


More information about the Tutor mailing list