diff --git a/Wrappers/Python/test/test_approximate_gradient.py b/Wrappers/Python/test/test_approximate_gradient.py index 86044a4759..c8ad954953 100644 --- a/Wrappers/Python/test/test_approximate_gradient.py +++ b/Wrappers/Python/test/test_approximate_gradient.py @@ -531,4 +531,14 @@ def test_LSVRG_toy_example_store_gradients(self): self.assertNumpyArrayAlmostEqual( alg_stochastic.x.as_array(), u_cvxpy.value, 3) self.assertNumpyArrayAlmostEqual( - alg_stochastic.x.as_array(), b.as_array(), 3) \ No newline at end of file + alg_stochastic.x.as_array(), b.as_array(), 3) + + def test_sampler_out_of_range(self): + def g(index): + return -2 + bad_sampler = Sampler.from_function(12,g) + f = self.stochastic_estimator([self.f]*10, bad_sampler, seed=25) + with self.assertRaises(IndexError): + f.gradient(self.initial) + f.gradient(self.initial) + \ No newline at end of file