@@ -142,72 +142,72 @@ def test_sample_inputs(self):
142142 def test_sample_on_dicts (self ):
143143 self .assertRaises (TypeError , self .gen .sample , dict .fromkeys ('abcdef' ), 2 )
144144
145- def test_weighted_choices (self ):
146- weighted_choices = self .gen .weighted_choices
145+ def test_choices (self ):
146+ choices = self .gen .choices
147147 data = ['red' , 'green' , 'blue' , 'yellow' ]
148148 str_data = 'abcd'
149149 range_data = range (4 )
150150 set_data = set (range (4 ))
151151
152152 # basic functionality
153153 for sample in [
154- weighted_choices (5 , data ),
155- weighted_choices (5 , data , range (4 )),
156- weighted_choices (k = 5 , population = data , weights = range (4 )),
157- weighted_choices (k = 5 , population = data , cum_weights = range (4 )),
154+ choices (5 , data ),
155+ choices (5 , data , range (4 )),
156+ choices (k = 5 , population = data , weights = range (4 )),
157+ choices (k = 5 , population = data , cum_weights = range (4 )),
158158 ]:
159159 self .assertEqual (len (sample ), 5 )
160160 self .assertEqual (type (sample ), list )
161161 self .assertTrue (set (sample ) <= set (data ))
162162
163163 # test argument handling
164- with self .assertRaises (TypeError ): # missing arguments
165- weighted_choices (2 )
164+ with self .assertRaises (TypeError ): # missing arguments
165+ choices (2 )
166166
167- self .assertEqual (weighted_choices (0 , data ), []) # k == 0
168- self .assertEqual (weighted_choices (- 1 , data ), []) # negative k behaves like ``[0] * -1``
167+ self .assertEqual (choices (0 , data ), []) # k == 0
168+ self .assertEqual (choices (- 1 , data ), []) # negative k behaves like ``[0] * -1``
169169 with self .assertRaises (TypeError ):
170- weighted_choices (2.5 , data ) # k is a float
170+ choices (2.5 , data ) # k is a float
171171
172- self .assertTrue (set (weighted_choices (5 , str_data )) <= set (str_data )) # population is a string sequence
173- self .assertTrue (set (weighted_choices (5 , range_data )) <= set (range_data )) # population is a range
172+ self .assertTrue (set (choices (5 , str_data )) <= set (str_data )) # population is a string sequence
173+ self .assertTrue (set (choices (5 , range_data )) <= set (range_data )) # population is a range
174174 with self .assertRaises (TypeError ):
175- weighted_choices (2.5 , set_data ) # population is not a sequence
175+ choices (2.5 , set_data ) # population is not a sequence
176176
177- self .assertTrue (set (weighted_choices (5 , data , None )) <= set (data )) # weights is None
178- self .assertTrue (set (weighted_choices (5 , data , weights = None )) <= set (data ))
177+ self .assertTrue (set (choices (5 , data , None )) <= set (data )) # weights is None
178+ self .assertTrue (set (choices (5 , data , weights = None )) <= set (data ))
179179 with self .assertRaises (ValueError ):
180- weighted_choices (5 , data , [1 ,2 ]) # len(weights) != len(population)
180+ choices (5 , data , [1 ,2 ]) # len(weights) != len(population)
181181 with self .assertRaises (IndexError ):
182- weighted_choices (5 , data , [0 ]* 4 ) # weights sum to zero
182+ choices (5 , data , [0 ]* 4 ) # weights sum to zero
183183 with self .assertRaises (TypeError ):
184- weighted_choices (5 , data , 10 ) # non-iterable weights
184+ choices (5 , data , 10 ) # non-iterable weights
185185 with self .assertRaises (TypeError ):
186- weighted_choices (5 , data , [None ]* 4 ) # non-numeric weights
186+ choices (5 , data , [None ]* 4 ) # non-numeric weights
187187 for weights in [
188188 [15 , 10 , 25 , 30 ], # integer weights
189189 [15.1 , 10.2 , 25.2 , 30.3 ], # float weights
190190 [Fraction (1 , 3 ), Fraction (2 , 6 ), Fraction (3 , 6 ), Fraction (4 , 6 )], # fractional weights
191191 [True , False , True , False ] # booleans (include / exclude)
192192 ]:
193- self .assertTrue (set (weighted_choices (5 , data , weights )) <= set (data ))
193+ self .assertTrue (set (choices (5 , data , weights )) <= set (data ))
194194
195195 with self .assertRaises (ValueError ):
196- weighted_choices (5 , data , cum_weights = [1 ,2 ]) # len(weights) != len(population)
196+ choices (5 , data , cum_weights = [1 ,2 ]) # len(weights) != len(population)
197197 with self .assertRaises (IndexError ):
198- weighted_choices (5 , data , cum_weights = [0 ]* 4 ) # cum_weights sum to zero
198+ choices (5 , data , cum_weights = [0 ]* 4 ) # cum_weights sum to zero
199199 with self .assertRaises (TypeError ):
200- weighted_choices (5 , data , cum_weights = 10 ) # non-iterable cum_weights
200+ choices (5 , data , cum_weights = 10 ) # non-iterable cum_weights
201201 with self .assertRaises (TypeError ):
202- weighted_choices (5 , data , cum_weights = [None ]* 4 ) # non-numeric cum_weights
202+ choices (5 , data , cum_weights = [None ]* 4 ) # non-numeric cum_weights
203203 with self .assertRaises (TypeError ):
204- weighted_choices (5 , data , range (4 ), cum_weights = range (4 )) # both weights and cum_weights
204+ choices (5 , data , range (4 ), cum_weights = range (4 )) # both weights and cum_weights
205205 for weights in [
206206 [15 , 10 , 25 , 30 ], # integer cum_weights
207207 [15.1 , 10.2 , 25.2 , 30.3 ], # float cum_weights
208208 [Fraction (1 , 3 ), Fraction (2 , 6 ), Fraction (3 , 6 ), Fraction (4 , 6 )], # fractional cum_weights
209209 ]:
210- self .assertTrue (set (weighted_choices (5 , data , cum_weights = weights )) <= set (data ))
210+ self .assertTrue (set (choices (5 , data , cum_weights = weights )) <= set (data ))
211211
212212 def test_gauss (self ):
213213 # Ensure that the seed() method initializes all the hidden state. In
0 commit comments