Repository: numpy/numpy
File: numpy/random/tests/test_random.py (Python)

Code before:
        prng.set_state(state)
        new = prng.standard_normal(size=3)
        assert_(np.all(old == new))

    def test_backwards_compatibility(self):
        # Make sure we can accept old state tuples that do not have the
        # cached Gaussian value.
        prng, state = self._create_rng()
        old_state = state[:-2]
        x1 = prng.standard_normal(size=16)
        prng.set_state(old_state)
        x2 = prng.standard_normal(size=16)
        prng.set_state(state)
        x3 = prng.standard_normal(size=16)
        assert_(np.all(x1 == x2))
        assert_(np.all(x1 == x3))

    def test_negative_binomial(self):
        # Ensure that the negative binomial results take floating point
        # arguments without truncation.
        prng = self._create_rng()[0]
        prng.negative_binomial(0.5, 0.5)

    def test_set_invalid_state(self):
        # gh-25402
        prng = self._create_rng()[0]
        with pytest.raises(IndexError):
            prng.set_state(())


class TestRandint:

    rfunc = np.random.randint

    # valid integer/boolean types
    itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
             np.int32, np.uint32, np.int64, np.uint64]

    def test_unsupported_type(self):
        assert_raises(TypeError, self.rfunc, 1, dtype=float)

    def test_bounds_checking(self):
        for dt in self.itype:
            lbnd = 0 if dt is np.bool else np.iinfo(dt).min
            ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
            assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1, dtype=dt)
            assert_raises(ValueError, self.rfunc, ubnd, lbnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, 1, 0, dtype=dt)

    def test_rng_zero_and_extremes(self):

Review comment (suggestion):
```suggestion
        prng, _ = self._create_rng()
```

Code after:
        prng.set_state(state)
        new = prng.standard_normal(size=3)
        assert_(np.all(old == new))

    def test_backwards_compatibility(self):
        # Make sure we can accept old state tuples that do not have the
        # cached Gaussian value.
        prng, state = self._create_rng()
        old_state = state[:-2]
        x1 = prng.standard_normal(size=16)
        prng.set_state(old_state)
        x2 = prng.standard_normal(size=16)
        prng.set_state(state)
        x3 = prng.standard_normal(size=16)
        assert_(np.all(x1 == x2))
        assert_(np.all(x1 == x3))

    def test_negative_binomial(self):
        # Ensure that the negative binomial results take floating point
        # arguments without truncation.
        prng, _ = self._create_rng()
        prng.negative_binomial(0.5, 0.5)

    def test_set_invalid_state(self):
        # gh-25402
        prng, _ = self._create_rng()
        with pytest.raises(IndexError):
            prng.set_state(())


class TestRandint:

    rfunc = np.random.randint

    # valid integer/boolean types
    itype = [np.bool, np.int8, np.uint8, np.int16, np.uint16,
             np.int32, np.uint32, np.int64, np.uint64]

    def test_unsupported_type(self):
        assert_raises(TypeError, self.rfunc, 1, dtype=float)

    def test_bounds_checking(self):
        for dt in self.itype:
            lbnd = 0 if dt is np.bool else np.iinfo(dt).min
            ubnd = 2 if dt is np.bool else np.iinfo(dt).max + 1
            assert_raises(ValueError, self.rfunc, lbnd - 1, ubnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, lbnd, ubnd + 1, dtype=dt)
            assert_raises(ValueError, self.rfunc, ubnd, lbnd, dtype=dt)
            assert_raises(ValueError, self.rfunc, 1, 0, dtype=dt)

    def test_rng_zero_and_extremes(self):