@@ -156,6 +156,15 @@ def test_bounds_checking(self):
156
156
assert_raises (ValueError , self .rfunc , ubnd , lbnd , dtype = dt )
157
157
assert_raises (ValueError , self .rfunc , 1 , 0 , dtype = dt )
158
158
159
+ def test_bounds_checking_array (self ):
160
+ for dt in self .itype :
161
+ lbnd = 0 if dt is bool else np .iinfo (dt ).min
162
+ ubnd = 2 if dt is bool else np .iinfo (dt ).max + 1
163
+ assert_raises (ValueError , self .rfunc , [lbnd - 1 ], [ubnd ], dtype = dt )
164
+ assert_raises (ValueError , self .rfunc , [lbnd ], [ubnd + 1 ], dtype = dt )
165
+ assert_raises (ValueError , self .rfunc , ubnd , [lbnd ], dtype = dt )
166
+ assert_raises (ValueError , self .rfunc , [1 ], 0 , dtype = dt )
167
+
159
168
def test_rng_zero_and_extremes (self ):
160
169
for dt in self .itype :
161
170
lbnd = 0 if dt is bool else np .iinfo (dt ).min
@@ -170,6 +179,21 @@ def test_rng_zero_and_extremes(self):
170
179
tgt = (lbnd + ubnd ) // 2
171
180
assert_equal (self .rfunc (tgt , tgt + 1 , size = 1000 , dtype = dt ), tgt )
172
181
182
+ def test_rng_zero_and_extremes_array (self ):
183
+ for dt in self .itype :
184
+ lbnd = 0 if dt is bool else np .iinfo (dt ).min
185
+ ubnd = 2 if dt is bool else np .iinfo (dt ).max + 1
186
+
187
+ tgt = ubnd - 1
188
+ print (dt )
189
+ assert_equal (self .rfunc ([tgt ], [tgt + 1 ], size = 1000 , dtype = dt ), tgt )
190
+
191
+ tgt = lbnd
192
+ assert_equal (self .rfunc ([tgt ], [tgt + 1 ], size = 1000 , dtype = dt ), tgt )
193
+
194
+ tgt = (lbnd + ubnd ) // 2
195
+ assert_equal (self .rfunc ([tgt ], [tgt + 1 ], size = 1000 , dtype = dt ), tgt )
196
+
173
197
def test_full_range (self ):
174
198
# Test for ticket #1690
175
199
@@ -184,6 +208,20 @@ def test_full_range(self):
184
208
"but one was with the following "
185
209
"message:\n \n %s" % str (e ))
186
210
211
+ def test_full_range_array (self ):
212
+ # Test for ticket #1690
213
+
214
+ for dt in self .itype :
215
+ lbnd = 0 if dt is bool else np .iinfo (dt ).min
216
+ ubnd = 2 if dt is bool else np .iinfo (dt ).max + 1
217
+
218
+ try :
219
+ self .rfunc ([lbnd ], [ubnd ], dtype = dt )
220
+ except Exception as e :
221
+ raise AssertionError ("No error should have been raised, "
222
+ "but one was with the following "
223
+ "message:\n \n %s" % str (e ))
224
+
187
225
def test_in_bounds_fuzz (self ):
188
226
# Don't use fixed seed
189
227
mt19937 .seed ()
@@ -275,6 +313,17 @@ def test_respect_dtype_singleton(self):
275
313
self .assertEqual (type (sample ), dt )
276
314
277
315
316
+ def test_respect_dtype_array (self ):
317
+ # See gh-7203
318
+ for dt in self .itype :
319
+ lbnd = 0 if dt is bool else np .iinfo (dt ).min
320
+ ubnd = 2 if dt is bool else np .iinfo (dt ).max + 1
321
+ dt = np .bool_ if dt is bool else dt
322
+
323
+ sample = self .rfunc ([lbnd ], [ubnd ], dtype = dt )
324
+ self .assertEqual (sample .dtype , dt )
325
+
326
+
278
327
class TestRandomDist (TestCase ):
279
328
# Make sure the random distribution returns the correct value for a
280
329
# given seed
0 commit comments