def test_RP_sexes_roughly_even(self): sexes_variation_percent = 15.0 name = RandomPerson().gendered_name() sex_count = Counter() for contact in range(self.binary_check_sample_size): p = name.next() sex_count[p['Sex']] += 1 print sex_count.items() # check sexes are equally numbered to within a reasonable tolerance (e.g. 10%) # Males outnumber females by a percentage point or two self.assertAlmostEqual( sex_count['male'] + 2.0/100.0 * self.binary_check_sample_size, sex_count['female'], delta=self.binary_check_sample_size * sexes_variation_percent / 100.0 + 1.0)
def test_RP_NoBlankNames(self): """ over a good-sized sample check RandomPerson doesn't emit any blank names """ def null_or_blank(s): return not s.strip(' \r\t\n') name = RandomPerson().gendered_name() for contact in range(self.medium_sample_size): n = name.next() cnt = 0 # check all name and sex fields are non-blank for i in n.items(): cnt += 1 self.assertFalse(null_or_blank(i[1]))