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

Code before:
        # cached Gaussian is restored.
        random_state, state = self._create_state()
        random_state.standard_normal()
        state = random_state.get_state()
        old = random_state.standard_normal(size=3)
        random_state.set_state(state)
        new = random_state.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.
        random_state, state = self._create_state()
        old_state = state[:-2]
        x1 = random_state.standard_normal(size=16)
        random_state.set_state(old_state)
        x2 = random_state.standard_normal(size=16)
        random_state.set_state(state)
        x3 = random_state.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.
        random_state = self._create_state()[0]
        random_state.negative_binomial(0.5, 0.5)

    def test_get_state_warning(self):
        rs = random.RandomState(PCG64())
        with pytest.warns(RuntimeWarning):
            state = rs.get_state()
        assert isinstance(state, dict)
        assert state['bit_generator'] == 'PCG64'

    def test_invalid_legacy_state_setting(self):
        random_state, state = self._create_state()
        state = random_state.get_state()
        new_state = ('Unknown', ) + state[1:]
        assert_raises(ValueError, random_state.set_state, new_state)
        assert_raises(TypeError, random_state.set_state,
                      np.array(new_state, dtype=object))
        state = random_state.get_state(legacy=False)
        del state['bit_generator']
        assert_raises(ValueError, random_state.set_state, state)

    def test_pickle(self):
        random_state = self._create_state()[0]
        random_state.seed(0)
        random_state.random_sample(100)
        random_state.standard_normal()

Review comment (suggestion):
```suggestion
        random_state, _ = self._create_state()
```

Code after:
        # cached Gaussian is restored.
        random_state, state = self._create_state()
        random_state.standard_normal()
        state = random_state.get_state()
        old = random_state.standard_normal(size=3)
        random_state.set_state(state)
        new = random_state.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.
        random_state, state = self._create_state()
        old_state = state[:-2]
        x1 = random_state.standard_normal(size=16)
        random_state.set_state(old_state)
        x2 = random_state.standard_normal(size=16)
        random_state.set_state(state)
        x3 = random_state.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.
        random_state, _ = self._create_state()
        random_state.negative_binomial(0.5, 0.5)

    def test_get_state_warning(self):
        rs = random.RandomState(PCG64())
        with pytest.warns(RuntimeWarning):
            state = rs.get_state()
        assert isinstance(state, dict)
        assert state['bit_generator'] == 'PCG64'

    def test_invalid_legacy_state_setting(self):
        random_state, state = self._create_state()
        state = random_state.get_state()
        new_state = ('Unknown', ) + state[1:]
        assert_raises(ValueError, random_state.set_state, new_state)
        assert_raises(TypeError, random_state.set_state,
                      np.array(new_state, dtype=object))
        state = random_state.get_state(legacy=False)
        del state['bit_generator']
        assert_raises(ValueError, random_state.set_state, state)

    def test_pickle(self):
        random_state, _ = self._create_state()
        random_state.seed(0)
        random_state.random_sample(100)
        random_state.standard_normal()