[SciPy-Dev] adding test to test_random.py
Vincent Davis
vincent@vincentdavis....
Sun Jun 13 19:23:25 CDT 2010
On Sun, Jun 13, 2010 at 6:20 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
> On Sun, Jun 13, 2010 at 5:10 PM, Robert Kern <robert.kern@gmail.com> wrote:
>> On Sun, Jun 13, 2010 at 18:59, Vincent Davis <vincent@vincentdavis.net> wrote:
>>> I was thinking that I could add a test to test_random.py withing numpy
>>> to test rand(), randn()..
>>> I added a few tests and modified/saved it to my currently install
>>> numpy. The test should fail but I get no failed tests. I guess there
>>> is something I don't know :)
>
> The test count will tell you if your test ran.
>
>>> I added (assert 1==2 #just to make sure it fails :) but the randn
>>> test should also fail.
>>>
>>> class TestRandomDist(TestCase):
>>> """ Make sure the random distrobution return the correct value for a
>>> given seed
>>> """
>>> self.seed = 1234567890
>>
>> This is not correct. At the class level, there is no "self".
>
> You could do:
>
> def setUp(self):
> self.seed = 1234567890
>
>>> def test_rand(self):
>>> np.random.seed(self.seed)
>>> actual = np.random.rand(3,3)
>>> desired = array([[ 0.61879477, 0.59162363, 0.88868359],
>>> [ 0.8916548 , 0.45756748, 0.77818808],
>>> [ 0.26706377, 0.99610621, 0.54009489]])
>>
>> These are not full precision. Use set_print_options() to raise the
>> precision to 17 before printing out the desired results.
>>
>>> assert actual == desired
>>
>> Do not use asserts; they are turned off in optimized .pyo compiled
>> bytecode. Use np.testing.assert_array_equal(). This may or may not be
>> the reason you are not seeing the failures you are expecting. Run the
>> test suite with some verbosity so that the names of the test functions
>> will print out.
>
> np.testing.assert_array_equal() has nice output. But even if you went
> with a straight assert such as self.assert_, you'd need reduce the
> truth using all: (actual == desired).all()
Thanks for the recommendations, how do I run the test in a more
verbose way. I am google how to do this now.
Thanks again
Vincent
>
>> --
>> Robert Kern
>>
>> "I have come to believe that the whole world is an enigma, a harmless
>> enigma that is made terrible by our own mad attempt to interpret it as
>> though it had an underlying truth."
>> -- Umberto Eco
>> _______________________________________________
>> SciPy-Dev mailing list
>> SciPy-Dev@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-dev
>>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
More information about the SciPy-Dev
mailing list