Example #1
0
 def test_choose_population_bool(self):
     a = 0
     for ii in range(200):
         if util.choose_population(util.nonce()):
             a += 1
     # Make sure it's relatively uniform...
     self.assertRoughly(a, 100)
Example #2
0
 def test_choose_population_bool(self):
     a = 0
     for ii in range(200):
         if util.choose_population(util.nonce()):
             a += 1
     # Make sure it's relatively uniform...
     self.assertRoughly(a, 100)
Example #3
0
 def test_choose_population_list(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(),
                                         ['foo', 'bar', 'baz'])
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 100)
     self.assertRoughly(counts['bar'], 100)
     self.assertRoughly(counts['baz'], 100)
Example #4
0
 def test_choose_population_list(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(),
                                         ['foo', 'bar', 'baz'])
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 100)
     self.assertRoughly(counts['bar'], 100)
     self.assertRoughly(counts['baz'], 100)
Example #5
0
 def test_choose_population_weighted(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(), {'foo': 0.1,
                                                        'quux': 0,
                                                        'bar': 0.1,
                                                        'baz': 0.8})
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 30)
     self.assertRoughly(counts['bar'], 30)
     self.assertRoughly(counts['baz'], 240)
     self.assertEqual(counts['quux'], 0)
Example #6
0
 def test_choose_population_weighted(self):
     counts = defaultdict(int)
     for ii in range(300):
         choice = util.choose_population(util.nonce(), {
             'foo': 0.1,
             'quux': 0,
             'bar': 0.1,
             'baz': 0.8
         })
         counts[choice] += 1
     self.assertRoughly(counts['foo'], 30)
     self.assertRoughly(counts['bar'], 30)
     self.assertRoughly(counts['baz'], 240)
     self.assertEqual(counts['quux'], 0)
Example #7
0
 def test_choose_population_zero_mass(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), {'foo': 0})
Example #8
0
 def test_chose_population_bad_value(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), 123)
Example #9
0
 def test_choose_population_zero_mass(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), {'foo': 0})
Example #10
0
 def test_chose_population_bad_value(self):
     with self.assertRaises(ValueError):
         util.choose_population(util.nonce(), 123)