[Tutor] unitest with random inputs

Mats Wichmann mats at wichmann.us
Wed Jul 19 14:26:18 EDT 2017

On 07/19/2017 10:55 AM, Sydney Shall wrote:
> On 19/07/2017 18:42, Steven D'Aprano wrote:
>> On Wed, Jul 19, 2017 at 05:01:53PM +0200, Sydney Shall wrote:
>> [...]
>>>   def test_zero_in_capitalsadvanced(self):
>>>          self.assertIn(self.capitalsadvanced, 0.0)
>>> The error message is:
>>> Traceback (most recent call last):
>> [...]
>>> in assertIn
>>>      if member not in container:
>>> TypeError: argument of type 'float' is not iterable
>> You are trying to test whether capitalsadvanced is in 0.0. Reverse the
>> arguments:
>>          self.assertIn(0.0, self.capitalsadvanced)
>> which will test whether 0.0 is in self.capitalsadvanced.
>>> FAILED (failures=9, errors=1)
>>> The failures all arise from a 'nan'.
>>> It is this problem that I am trying to resolve.
>> Well, since you don't show us what those failing tests are, we cannot
>> possibly tell you how to fix them.
>> Start by showing us *one* failing test, and what the failure is.
> Thank you Steve.
> The remaining 'nan' problems are shown below.
> runfile('/Users/sydney/Capital/Capital_with_productivity/Current_Versions/testPOCWP_V2.py',
> wdir='/Users/sydney/Capital/Capital_with_productivity/Current_Versions')
> /Users/sydney/Capital/Capital_with_productivity/Current_Versions/PopulationOfCapitalsWithProductivityV16_Python36.py:1582:
> RuntimeWarning: invalid value encountered in true_divide

The thing to remember is that NaN is actually... _not_ a number,
literally.  If you like to think in terms of exceptions, then NaN is lan
exception - some thing caused a result which cannot be represented as a
number, and so this magical value is used to tell you.  Thus, no numeric
operations can be done on it.  This is not from Python... this is the
way it was defined in the IEEE standard (754 if memory serves), Python
just tries to implement the requirements of that standard as best it
can.  (turns out Python actually has two flavors: a quiet NaN, and a
signaling NaN).

sorry there wasn't much Python content in this message :)

More information about the Tutor mailing list