Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36632
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Subject | Re: Probabilistic unit tests? |
| Newsgroups | comp.lang.python |
| References | <b312f3e7-5c73-486e-925e-da8343963fb6@googlegroups.com> |
| Message-ID | <M2XHs.7436$eK2.3641@fx31.fr7> (permalink) |
| Organization | virginmedia.com |
| Date | 2013-01-11 16:26 +0000 |
On Thu, 10 Jan 2013 17:59:05 -0800, Nick Mellor wrote: > Hi, > > I've got a unit test that will usually succeed but sometimes fails. An > occasional failure is expected and fine. It's failing all the time I > want to test for. > > What I want to test is "on average, there are the same number of males > and females in a sample, give or take 2%." > > Here's the unit test code: > import unittest from collections import counter > > sex_count = Counter() > for contact in range(self.binary_check_sample_size): > p = get_record_as_dict() > sex_count[p['Sex']] += 1 > self.assertAlmostEqual(sex_count['male'], > sex_count['female'], delta=sample_size * 2.0 / > 100.0) > > My question is: how would you run an identical test 5 times and pass the > group *as a whole* if only one or two iterations passed the test? > Something like: > > for n in range(5): > # self.assertAlmostEqual(...) > # if test passed: break > else: > self.fail() > > (except that would create 5+1 tests as written!) > > Thanks for any thoughts, > > Best wishes, > > Nick unit test are for testing your code, not checking if input data is in the correct range so unless you are writing a program intended to generate test data I don't see why unit test are appropriate in this case. -- Under capitalism, man exploits man. Under communism, it's just the opposite. -- J.K. Galbraith
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Probabilistic unit tests? Nick Mellor <thebalancepro@gmail.com> - 2013-01-10 17:59 -0800
Re: Probabilistic unit tests? Roy Smith <roy@panix.com> - 2013-01-10 21:22 -0500
Re: Probabilistic unit tests? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-11 03:34 +0000
Re: Probabilistic unit tests? alex23 <wuwei23@gmail.com> - 2013-01-12 00:07 -0800
Re: Probabilistic unit tests? Roy Smith <roy@panix.com> - 2013-01-12 09:22 -0500
Re: Probabilistic unit tests? duncan smith <buzzard@invalid.invalid> - 2013-01-12 18:08 +0000
Re: Probabilistic unit tests? Alister <alister.ware@ntlworld.com> - 2013-01-11 16:26 +0000
Re: Probabilistic unit tests? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-11 17:46 +0000
Re: Probabilistic unit tests? duncan smith <buzzard@invalid.invalid> - 2013-01-11 18:05 +0000
csiph-web