Exemple #1
0
    def test_random_from_uniform_dist(self):
        # Test is probabilistic, which is not great, but is necessary.
        simulation_pmf = PMF()
        for n in range(10000):
            x = self.pmf.random()
            hit_count = simulation_pmf.get(x, 0)
            simulation_pmf[x] = hit_count + 1
        simulation_pmf.normalize()

        for x in "abcde":
            self.assertTrue(0.190 < simulation_pmf[x] < 0.210)
Exemple #2
0
    def test_random_from_uniform_dist(self):
        # Test is probabilistic, which is not great, but is necessary.
        simulation_pmf = PMF()
        for n in range(10000):
            x = self.pmf.random()
            hit_count = simulation_pmf.get(x, 0)
            simulation_pmf[x] = hit_count + 1
        simulation_pmf.normalize()

        for x in 'abcde':
            self.assertTrue(0.190 < simulation_pmf[x] < 0.210)
Exemple #3
0
    def test_random_from_power_dist(self):
        # Test is probabilistic, which is not great, but is necessary.
        self.pmf.power_law_dist(xrange(1, 4))
        simulation_pmf = PMF()
        for n in range(10000):
            x = self.pmf.random()
            hit_count = simulation_pmf.get(x, 0)
            simulation_pmf[x] = hit_count + 1
        simulation_pmf.normalize()

        self.assertTrue(0.540 < simulation_pmf[1] < 0.550)
        self.assertTrue(0.262 < simulation_pmf[2] < 0.283)
        self.assertTrue(0.166 < simulation_pmf[3] < 0.197)
Exemple #4
0
    def test_random_from_power_dist(self):
        # Test is probabilistic, which is not great, but is necessary.
        self.pmf.power_law_dist(xrange(1, 4))
        simulation_pmf = PMF()
        for n in range(10000):
            x = self.pmf.random()
            hit_count = simulation_pmf.get(x, 0)
            simulation_pmf[x] = hit_count + 1
        simulation_pmf.normalize()

        self.assertTrue(0.540 < simulation_pmf[1] < 0.550)
        self.assertTrue(0.262 < simulation_pmf[2] < 0.283)
        self.assertTrue(0.166 < simulation_pmf[3] < 0.197)