code: def test_as_array():
      space = TargetSpace(target_func, PBOUNDS)
  
      x = space._as_array([0, 1])
      assert x.shape == (2,)
      assert all(x == np.array([0, 1]))
  
      x = space._as_array({"p2": 1, "p1": 2})
      assert x.shape == (2,)
      assert all(x == np.array([2, 1]))
  
      with pytest.raises(ValueError):
          x = space._as_array([2, 1, 7])
      with pytest.raises(ValueError):
          x = space._as_array({"p2": 1, "p1": 2, "other": 7})
      with pytest.raises(ValueError):
          x = space._as_array({"p2": 1})
      with pytest.raises(ValueError):
          x = space._as_array({"other": 7})
  
imports: import pytest
  import numpy
  from bayes_opt.constraint import ConstraintModel
  from bayes_opt.target_space import TargetSpace
  from bayes_opt.util import NotUniqueError
label_desc: Use image node_id 5 for calling a global function with example usage: test_as_array() without return types