def test_optimum_on_bounds(function, initial_point, bounds, actual, seed): random.seed(seed) np.random.seed(seed) solver = RvfSolver(function, initial_point, bounds) point, value = solver.anneal(max_steps=4000) # tolerances tol_point = 0.1 tol_value = 0.1 actual = np.array(actual) assert abs(value - function(*actual)) < tol_value assert helpers.distance(actual, point) < tol_point
def test_initialized_with_initial_point_out_of_bounds(function, point, bounds): with pytest.raises(ValueError): RvfSolver(function, point, bounds)
def test_initialized_with_wrong_shapes(function, point, bounds): with pytest.raises(ValueError): RvfSolver(function, point, bounds)
def test_initialized_with_bad_objective(): with pytest.raises(ValueError): solver = RvfSolver(rvf_1_basic, [1], [[-1, 1]], objective="blah")
def test_initialized_with_bad_function(bad_value): with pytest.raises(TypeError): solver = RvfSolver(bad_value, [0, 0], [[-1, 1], [-1, 1]])
def test_initialized_with_bad_bounds(bad_value): with pytest.raises(ValueError): RvfSolver(rvf_1_basic, [1], bad_value)