class AvoidRepeatRandomizerTests(unittest.TestCase): def setUp(self): self.first = 0 self.last = 10 self.avoid_randomizer = AvoidRepeatRandomizer(self.first, self.last) def test_range(self): numbers_count = 2 * (self.last - self.first + 1) for _ in range(numbers_count): number = self.avoid_randomizer.next_random() self.assertTrue(self.first <= number <= self.last) def test_avoiding(self): def fill_set(): drawn_numbers = set() for _ in range(numbers_count): number = self.avoid_randomizer.next_random() drawn_numbers.add(number) return drawn_numbers numbers_count = self.last - self.first + 1 drawn_numbers = fill_set() self.assertEqual(len(drawn_numbers), numbers_count) drawn_numbers = fill_set() self.assertEqual(len(drawn_numbers), numbers_count)
def setUp(self): self.first = 0 self.last = 10 self.avoid_randomizer = AvoidRepeatRandomizer(self.first, self.last)