| 351 | assert_(vals.min() >= 0) |
| 352 | |
| 353 | def test_repeatability(self): |
| 354 | # We use a sha256 hash of generated sequences of 1000 samples |
| 355 | # in the range [0, 6) for all but bool, where the range |
| 356 | # is [0, 2). Hashes are for little endian numbers. |
| 357 | tgt = {'bool': '509aea74d792fb931784c4b0135392c65aec64beee12b0cc167548a2c3d31e71', # noqa: E501 |
| 358 | 'int16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4', # noqa: E501 |
| 359 | 'int32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f', # noqa: E501 |
| 360 | 'int64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e', # noqa: E501 |
| 361 | 'int8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404', # noqa: E501 |
| 362 | 'uint16': '7b07f1a920e46f6d0fe02314155a2330bcfd7635e708da50e536c5ebb631a7d4', # noqa: E501 |
| 363 | 'uint32': 'e577bfed6c935de944424667e3da285012e741892dcb7051a8f1ce68ab05c92f', # noqa: E501 |
| 364 | 'uint64': '0fbead0b06759df2cfb55e43148822d4a1ff953c7eb19a5b08445a63bb64fa9e', # noqa: E501 |
| 365 | 'uint8': '001aac3a5acb935a9b186cbe14a1ca064b8bb2dd0b045d48abeacf74d0203404'} # noqa: E501 |
| 366 | |
| 367 | for dt in self.itype[1:]: |
| 368 | rng = random.RandomState(1234) |
| 369 | |
| 370 | # view as little endian for hash |
| 371 | if sys.byteorder == 'little': |
| 372 | val = rng.randint(0, 6, size=1000, dtype=dt) |
| 373 | else: |
| 374 | val = rng.randint(0, 6, size=1000, dtype=dt).byteswap() |
| 375 | |
| 376 | res = hashlib.sha256(val.view(np.int8)).hexdigest() |
| 377 | assert_(tgt[np.dtype(dt).name] == res) |
| 378 | |
| 379 | # bools do not depend on endianness |
| 380 | rng = random.RandomState(1234) |
| 381 | val = rng.randint(0, 2, size=1000, dtype=bool).view(np.int8) |
| 382 | res = hashlib.sha256(val).hexdigest() |
| 383 | assert_(tgt[np.dtype(bool).name] == res) |
| 384 | |
| 385 | @pytest.mark.skipif(np.iinfo('l').max < 2**32, |
| 386 | reason='Cannot test with 32-bit C long') |