code: def test_single_constraint_lower_upper():
      def target_function(x, y):
          return np.cos(2 * x) * np.cos(y) + np.sin(x)
  
      def constraint_function(x, y):
          return np.cos(x) * np.cos(y) - np.sin(x) * np.sin(y)
  
      constraint_limit_lower = -0.5
      constraint_limit_upper = 0.5
  
      constraint = NonlinearConstraint(
          constraint_function,
          constraint_limit_lower,
          constraint_limit_upper,
      )
      pbounds = {"x": (0, 6), "y": (0, 6)}
  
      optimizer = BayesianOptimization(
          f=target_function,
          constraint=constraint,
          pbounds=pbounds,
          verbose=0,
          random_state=1,
      )
  
      assert optimizer.constraint.lb == constraint.lb
      assert optimizer.constraint.ub == constraint.ub
  
      optimizer.maximize(
          init_points=2,
          n_iter=10,
      )
  
      # Check limits
      assert (
          constraint_function(**optimizer.max["params"])
          <= constraint_limit_upper
      )
      assert (
          constraint_function(**optimizer.max["params"])
          >= constraint_limit_lower
      )
  
      # Exclude the last sampled point, because the constraint is not fitted on that.
      res = np.array(
          [
              [
                  r["target"],
                  r["constraint"],
                  r["params"]["x"],
                  r["params"]["y"],
              ]
              for r in optimizer.res[:-1]
          ]
      )
  
      xy = res[:, [2, 3]]
      x = res[:, 2]
      y = res[:, 3]
  
      # Check accuracy of approximation for sampled points
      assert constraint_function(x, y) == approx(
          optimizer.constraint.approx(xy), rel=1e-5, abs=1e-5
      )
      assert constraint_function(x, y) == approx(
          optimizer.space.constraint_values[:-1], rel=1e-5, abs=1e-5
      )
  
file_path: BayesianOptimization/tests/test_constraint.py
imports: import numpy
  from bayes_opt import BayesianOptimization
  from pytest import approx, raises
  from scipy.optimize import NonlinearConstraint
label_desc: Use image node_id 3 for calling a global function with example usage: test_single_constraint_lower_upper() and returns: unknown, unknown