docstr: Test the pool of available trials based on candidate_pool_ratio
docstr_tok: ["Test","the","pool","of","available","trials","based","on","candidate_pool_ratio"]
code: def test_truncate_valid_choice(
      self, candidate_pool_ratio, space, monkeypatch
  ):
      """Test the pool of available trials based on candidate_pool_ratio"""
      lineages = build_lineages_for_exploit(space, monkeypatch)
      trials = self.get_trials(lineages, TrialStub(objective=50))
      trials = sorted(trials, key=lambda trial: trial.objective.value)
  
      num_completed_trials = len(trials)
      valid_choices = numpy.arange(
          int(candidate_pool_ratio * num_completed_trials)
      ).tolist()
      selected_trial = trials[valid_choices[-1]]
  
      def mocked_choice(choices, *args, **kwargs):
          assert choices.tolist() == valid_choices
          return valid_choices[-1]
  
      rng = RNGStub()
      rng.choice = mocked_choice
  
      completed_trial_index = numpy.random.choice(range(len(trials)))
      completed_trial = trials[completed_trial_index]
  
      # Add non completed trials and shuffle the list to test it is filtered and sorted properly
      trials += space.sample(20, seed=2)
      numpy.random.shuffle(trials)
  
      exploit = self.constructor(
          truncation_quantile=0,
          candidate_pool_ratio=candidate_pool_ratio,
      )
  
      trial = exploit._truncate(
          rng,
          completed_trial,
          trials,
      )
  
      assert trial is selected_trial
  
imports: import numpy
  import pytest
  from base import RNGStub, TrialStub
  from orion.algo.pbt.exploit import BacktrackExploit, PipelineExploit, TruncateExploit
  from orion.algo.pbt.pbt import Lineages
label_desc: Use image node_id 8 for calling the TruncateGenericTests obj's underlying member method code with example usage: obj.test_truncate_valid_choice(candidate_pool_ratio, space, monkeypatch) and returns: valid_choices