Exemplo n.º 1
0
    def test_weights(self):
        items = [
            ('1', 2),
            ('2', 1),
            ('3', 1),
        ]

        r = Randomizer(items)
        r.force_different = False

        results = list()

        for x in range(10000):
            results.append(next(r))

        self.assertAlmostEqual(5000, results.count('1'), delta=500)
        self.assertAlmostEqual(2500, results.count('2'), delta=500)
        self.assertAlmostEqual(2500, results.count('3'), delta=500)

        items = [
            ('1', 1),
            ('2', 1),
            ('3', 3),
        ]

        r = Randomizer(items)
        r.force_different = False

        results = list()

        for x in range(10000):
            results.append(next(r))

        self.assertAlmostEqual(2000, results.count('1'), delta=500)
        self.assertAlmostEqual(2000, results.count('2'), delta=500)
        self.assertAlmostEqual(6000, results.count('3'), delta=500)

        items = [
            ('1', 1),
            ('2', 6),
            ('3', 3),
        ]

        r = Randomizer(items)
        r.force_different = False

        results = list()

        for x in range(10000):
            results.append(next(r))

        self.assertAlmostEqual(1000, results.count('1'), delta=500)
        self.assertAlmostEqual(6000, results.count('2'), delta=500)
        self.assertAlmostEqual(3000, results.count('3'), delta=500)
Exemplo n.º 2
0
    def test_force_different(self):

        items = [
            ('1', 1),
            ('2', 1),
            ('3', 1),
        ]

        r = Randomizer(items)
        r.force_different = True

        last_item = None
        for x in range(1000):
            this_item = next(r)
            self.assertNotEqual(this_item, last_item)
            last_item = this_item