code: def test_intersection_search_space() -> None:
      search_space = IntersectionSearchSpace()
      study = create_study()
  
      # No trial.
      assert search_space.calculate(study) == {}
      assert search_space.calculate(study) == intersection_search_space(
          study.get_trials(deepcopy=False)
      )
  
      # Waiting trial.
      study.enqueue_trial(
          {"y": 0, "x": 5},
          {"y": FloatDistribution(-3, 3), "x": IntDistribution(0, 10)},
      )
      assert search_space.calculate(study) == {}
      assert search_space.calculate(study) == intersection_search_space(
          study.get_trials(deepcopy=False)
      )
  
      # First trial.
      study.optimize(
          lambda t: t.suggest_float("y", -3, 3)
          + t.suggest_int("x", 0, 10),
          n_trials=1,
      )
      assert search_space.calculate(study) == {
          "x": IntDistribution(low=0, high=10),
          "y": FloatDistribution(low=-3, high=3),
      }
      assert search_space.calculate(study) == intersection_search_space(
          study.get_trials(deepcopy=False)
      )
  
      # Returned dict is sorted by parameter names.
      assert list(search_space.calculate(study).keys()) == ["x", "y"]
  
      # Second trial (only 'y' parameter is suggested in this trial).
      study.optimize(lambda t: t.suggest_float("y", -3, 3), n_trials=1)
      assert search_space.calculate(study) == {
          "y": FloatDistribution(low=-3, high=3)
      }
      assert search_space.calculate(study) == intersection_search_space(
          study.get_trials(deepcopy=False)
      )
  
      # Failed or pruned trials are not considered in the calculation of
      # an intersection search space.
      def objective(trial: Trial, exception: Exception) -> float:
          trial.suggest_float("z", 0, 1)
          raise exception
  
      study.optimize(
          lambda t: objective(t, RuntimeError()),
          n_trials=1,
          catch=(RuntimeError,),
      )
      study.optimize(lambda t: objective(t, TrialPruned()), n_trials=1)
      assert search_space.calculate(study) == {
          "y": FloatDistribution(low=-3, high=3)
      }
      assert search_space.calculate(study) == intersection_search_space(
          study.get_trials(deepcopy=False)
      )
  
      # If two parameters have the same name but different distributions,
      # those are regarded as different parameters.
      study.optimize(lambda t: t.suggest_float("y", -1, 1), n_trials=1)
      assert search_space.calculate(study) == {}
      assert search_space.calculate(study) == intersection_search_space(
          study.get_trials(deepcopy=False)
      )
  
      # The search space remains empty once it is empty.
      study.optimize(
          lambda t: t.suggest_float("y", -3, 3)
          + t.suggest_int("x", 0, 10),
          n_trials=1,
      )
      assert search_space.calculate(study) == {}
      assert search_space.calculate(study) == intersection_search_space(
          study.get_trials(deepcopy=False)
      )
  
file_path: optuna/tests/search_space_tests/test_intersection.py
imports: import pytest
  from optuna import create_study
  from optuna import TrialPruned
  from optuna.distributions import FloatDistribution
  from optuna.distributions import IntDistribution
  from optuna.search_space import intersection_search_space
  from optuna.search_space import IntersectionSearchSpace
  from optuna.testing.storages import StorageSupplier
  from optuna.trial import Trial
label_desc: Use image node_id 1 for calling a global function with example usage: test_intersection_search_space() without return types