예제 #1
0
 def test_choice_picks_all_items(self):
     # make sure all items of a sequence are picked (in the long run)
     sequence = [1, 2, 3, 4]
     picked = set()
     num = 10 ** 3
     src = SystemRandomSource(None)
     while num:
         picked.add(src.choice(sequence))
         if len(picked) == len(sequence):
             break
         num -= 1
     assert num > 0
예제 #2
0
 def test_choice_picks_all_items(self):
     # make sure all items of a sequence are picked (in the long run)
     sequence = [1, 2, 3, 4]
     picked = set()
     num = 10**3
     src = SystemRandomSource(None)
     while num:
         picked.add(src.choice(sequence))
         if len(picked) == len(sequence):
             break
         num -= 1
     assert num > 0
예제 #3
0
 def test_choice_accepts_list_of_strings(self):
     # the choice() method accepts lists of strings
     src = SystemRandomSource(None)
     assert src.choice(['foo', 'bar', 'baz']) in ['foo', 'bar', 'baz']
예제 #4
0
 def test_choice_accepts_list_of_chars(self):
     # the choice() method accepts lists of chars
     src = SystemRandomSource(None)
     assert src.choice(['a', 'b', 'c']) in ['a', 'b', 'c']
예제 #5
0
 def test_choice_accepts_tuples_of_numbers(self):
     # the choce() method accepts tuples of numbers
     src = SystemRandomSource(None)
     assert src.choice((1, 2, 3), ) in [1, 2, 3]
예제 #6
0
 def test_choice_accepts_lists_of_numbers(self):
     # the choice() method accepts lists of numbers
     src = SystemRandomSource(None)
     assert src.choice([1, 2, 3]) in [1, 2, 3]
예제 #7
0
 def test_choice_accepts_list_of_strings(self):
     # the choice() method accepts lists of strings
     src = SystemRandomSource(None)
     assert src.choice(['foo', 'bar', 'baz']) in ['foo', 'bar', 'baz']
예제 #8
0
 def test_choice_accepts_list_of_chars(self):
     # the choice() method accepts lists of chars
     src = SystemRandomSource(None)
     assert src.choice(['a', 'b', 'c']) in ['a', 'b', 'c']
예제 #9
0
 def test_choice_accepts_tuples_of_numbers(self):
     # the choce() method accepts tuples of numbers
     src = SystemRandomSource(None)
     assert src.choice((1, 2, 3), ) in [1, 2, 3]
예제 #10
0
 def test_choice_accepts_lists_of_numbers(self):
     # the choice() method accepts lists of numbers
     src = SystemRandomSource(None)
     assert src.choice([1, 2, 3]) in [1, 2, 3]
예제 #11
0
 def test_has_choice_method(self):
     # SystemRandomInstances provide a choice method
     src = SystemRandomSource(None)
     assert hasattr(src, 'choice')
예제 #12
0
 def test_options_are_stored(self):
     # options passed-in are stored with SystemRandomStource instances
     options = "fake_options"
     src = SystemRandomSource(options)
     assert src.options is options