예제 #1
0
 def setUp(self):
     # Generate random results, calculate intermediate values for those
     # results.
     self.random_results = [random.choice(THINGS) for _ in range(50)]
     self.past_counts = oracle.count_past_events(
         self.random_results, LARGE_WINDOW)
     self.weights = oracle.calculate_weights(
         THINGS, self.past_counts, LARGE_WINDOW)
     self.cdf = oracle.calculate_cdf(self.weights)
     self.random_thing = oracle.sample_cdf(self.cdf)
예제 #2
0
 def test_calculate_cdf(self):
     # Simple case.
     weights = {'a': 0.25, 'b': 0.25, 'c': 0.25, 'd': 0.25}
     self.assertEqual({0.25: 'a', 0.5: 'b', 0.75: 'c',
                       1.0: 'd'}, oracle.calculate_cdf(weights))
     # All keys of cdf should be values in [0,1] range.
     self.assertNotIn(False, [1 >= t >= 0 for t in self.cdf])
     # All values of cdf should be THINGS.
     self.assertNotIn(
         False, [
             thing in THINGS for thing in self.cdf.values()])