code: def test_CrossValidate(self) -> None:
      # Prepare input and output data
      ma = mock.MagicMock()
      ma.get_training_data = mock.MagicMock(
          "ax.modelbridge.base.ModelBridge.get_training_data",
          autospec=True,
          return_value=self.training_data,
      )
      ma.cross_validate = mock.MagicMock(
          "ax.modelbridge.base.ModelBridge.cross_validate",
          autospec=True,
          return_value=self.observation_data,
      )
      # Do cross validation
      with self.assertRaises(ValueError):
          cross_validate(model=ma, folds=4)
      with self.assertRaises(ValueError):
          cross_validate(model=ma, folds=0)
      # First 2-fold
      result = cross_validate(model=ma, folds=2)
      self.assertEqual(len(result), 4)
      # Check that ModelBridge.cross_validate was called correctly.
      z = ma.cross_validate.mock_calls
      self.assertEqual(len(z), 2)
      train = [
          [
              obs.features.parameters["x"]
              for obs in r[2]["cv_training_data"]
          ]
          for r in z
      ]
      test = [
          [obsf.parameters["x"] for obsf in r[2]["cv_test_points"]]
          for r in z
      ]
      # Test no overlap between train and test sets, and all points used
      for i in range(2):
          self.assertEqual(len(set(train[i]).intersection(test[i])), 0)
          self.assertEqual(len(train[i]) + len(test[i]), 4)
      # Test all points used as test points
      # pyre-fixme[6]: For 1st param expected `Collection[ndarray]` but got
      #  `List[List[typing.Any]]`.
      all_test = np.hstack(test)
      self.assertTrue(
          np.array_equal(
              sorted(all_test), np.array([2.0, 2.0, 3.0, 4.0])
          )
      )
  
      # Test LOO
      result = cross_validate(model=ma, folds=-1)
      self.assertEqual(len(result), 4)
      z = ma.cross_validate.mock_calls[2:]
      self.assertEqual(len(z), 3)
      train = [
          [
              obs.features.parameters["x"]
              for obs in r[2]["cv_training_data"]
          ]
          for r in z
      ]
      test = [
          [obsf.parameters["x"] for obsf in r[2]["cv_test_points"]]
          for r in z
      ]
      # Test no overlap between train and test sets, and all points used
      for i in range(3):
          self.assertEqual(len(set(train[i]).intersection(test[i])), 0)
          self.assertEqual(len(train[i]) + len(test[i]), 4)
      # Test all points used as test points
      # pyre-fixme[6]: For 1st param expected `Collection[ndarray]` but got
      #  `List[List[typing.Any]]`.
      all_test = np.hstack(test)
      self.assertTrue(
          np.array_equal(
              sorted(all_test), np.array([2.0, 2.0, 3.0, 4.0])
          )
      )
      # Test selector
  
      # pyre-fixme[3]: Return type must be annotated.
      # pyre-fixme[2]: Parameter must be annotated.
      def test_selector(obs):
          return obs.features.parameters["x"] != 4.0
  
      result = cross_validate(
          model=ma, folds=-1, test_selector=test_selector
      )
      self.assertEqual(len(result), 3)
      z = ma.cross_validate.mock_calls[5:]
      self.assertEqual(len(z), 2)
      all_test = np.hstack(
          # pyre-fixme[6]: For 1st param expected `Collection[ndarray]` but got
          #  `List[List[typing.Any]]`.
          [
              [obsf.parameters["x"] for obsf in r[2]["cv_test_points"]]
              for r in z
          ]
      )
      self.assertTrue(
          np.array_equal(sorted(all_test), np.array([2.0, 2.0, 3.0]))
      )
  
imports: from typing import List
  from unittest import mock
  import numpy
  from ax.core.metric import Metric
  from ax.core.objective import MultiObjective, Objective
  from ax.core.observation import Observation, ObservationData, ObservationFeatures
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig, OptimizationConfig
  from ax.core.outcome_constraint import OutcomeConstraint
  from ax.core.types import ComparisonOp
  from ax.modelbridge.cross_validation import assess_model_fit, compute_diagnostics, cross_validate, cross_validate_by_trial, CVDiagnostics, CVResult, has_good_opt_config_model_fit, SingleDiagnosticBestModelSelector
  from ax.modelbridge.registry import Models
  from ax.utils.common.testutils import TestCase
  from ax.utils.testing.core_stubs import get_branin_experiment
label_desc: Use image node_id 2 for calling the CrossValidationTest obj's underlying member method code with example usage: obj.test_CrossValidate() and returns: unknown