[Tutor] unitest with random inputs

Sydney Shall s.shall at virginmedia.com
Wed Jul 19 13:09:22 EDT 2017


On 19/07/2017 18:56, Steven D'Aprano wrote:
> On Wed, Jul 19, 2017 at 06:08:57PM +0200, Sydney Shall wrote:
> 
>> 
> 
> (I haven't tested that code myself, so please try it, and if it doesn't
> work for some reason, let us know on the mailing list and somebody can
> fix it.)
> 
> But... I'm rather surprised that you need this test. Are you sure that
> your array capitalsadvanced will *always* contain at least one Not A
> Number value? Unless you put one in yourself, NANs generally indicate
> that a mathematical error has occurred somewhere.
> 

Steven,

Thanks again.

I started this precisely because I also thought and still think, that 
the origin of my problem is a mathematical error somewhere.

However, when I use predetermined input values, the errors are absent. 
They only appear when I use the random function. Although it should not 
be the case, I wondered whether the random function was feeding in a 
zero, because the errors seem to involve an invalid value after a 
true-divide according to some of the error reports earlier. So, my first 
step was to try and see if there are any zeros in the array that is used 
first. The tests say that the type and the length of the array is 
correct. But how do I test for a zero in a numpy.ndarray?


-- 
Sydney


More information about the Tutor mailing list