def testTwoElementDistribution(self):
        dist = {1: 50.0, 10: 50.0}
        iter = object_storage_api_tests.SizeDistributionIterator(dist)

        with mock.patch(random.__name__ + '.random') as rand:
            rand.side_effect = [0.2, 0.7, 0.2]
            values = list(itertools.islice(iter, 3))
            self.assertTrue(values == [1, 10, 1])
    def testPointDistribution(self):
        dist = {10: 100.0}

        iter = object_storage_api_tests.SizeDistributionIterator(dist)

        values = list(itertools.islice(iter, 5))

        self.assertEqual(values, [10, 10, 10, 10, 10])
    def testNonTerminatingBinaryPercent(self):
        # 20/100 = 1/5 does not terminate in binary
        dist = {1: 20.0, 10: 80.0}
        iter = object_storage_api_tests.SizeDistributionIterator(dist)

        with mock.patch(random.__name__ + '.random') as rand:
            rand.side_effect = [0.1, 0.9]
            values = list(itertools.islice(iter, 2))

            self.assertTrue(values == [1, 10])