def test_dtype2(self, dtype):
dtype = numpy.dtype(dtype)
# randint does not support 64 bit integers
if dtype in (numpy.int64, numpy.uint64):
return
iinfo = numpy.iinfo(dtype)
size = (10000,)
x = random.randint(iinfo.min, iinfo.max + 1, size, dtype)
self.assertEqual(x.dtype, dtype)
self.assertLessEqual(iinfo.min, min(x))
self.assertLessEqual(max(x), iinfo.max)
# Lower bound check
with self.assertRaises(ValueError):
random.randint(iinfo.min - 1, iinfo.min + 10, size, dtype)
# Upper bound check
with self.assertRaises(ValueError):
random.randint(iinfo.max - 10, iinfo.max + 2, size, dtype)
评论列表
文章目录