code: def test_truncation_discrete_random(op_type, lower, upper):
      p = 0.2
      geometric_op = (
          icdf_geometric if op_type == "icdf" else rejection_geometric
      )
  
      x = geometric_op(p, name="x", size=500)
      xt = Truncated.dist(x, lower=lower, upper=upper)
      assert isinstance(xt.owner.op, TruncatedRV)
  
      xt_draws = draw(xt)
      assert np.all(xt_draws >= lower)
      assert np.all(xt_draws <= upper)
      assert np.any(xt_draws == (max(1, lower)))
      if upper != np.inf:
          assert np.any(xt_draws == upper)
  
      # Test max_n_steps
      xt = Truncated.dist(x, lower=lower, upper=upper, max_n_steps=3)
      if op_type == "icdf":
          xt_draws = draw(xt)
          assert np.all(xt_draws >= lower)
          assert np.all(xt_draws <= upper)
          assert np.any(xt_draws == (max(1, lower)))
          if upper != np.inf:
              assert np.any(xt_draws == upper)
      else:
          with pytest.raises(
              TruncationError, match="^Truncation did not converge"
          ):
              # Rejections sampling with probability = (1 - p ** max_n_steps) ** sample_size =
              # = (1 - 0.2 ** 3) ** 500 = 0.018
              # Still, this probability can be too high to make this test pass with any seed.
              draw(xt, random_seed=2297228)
  
imports: import numpy
  import pytensor
  import pytensor.tensor
  import pytest
  import scipy
  from pytensor.tensor.random.basic import GeometricRV, NormalRV
  from pymc import Censored, Model, draw, find_MAP
  from pymc.distributions.continuous import Exponential, Gamma, TruncatedNormal, TruncatedNormalRV
  from pymc.distributions.shape_utils import change_dist_size
  from pymc.distributions.transforms import _default_transform
  from pymc.distributions.truncated import Truncated, TruncatedRV, _truncated
  from pymc.exceptions import TruncationError
  from pymc.logprob.abstract import _icdf
  from pymc.logprob.basic import logcdf, logp
  from pymc.logprob.transforms import IntervalTransform
  from pymc.logprob.utils import ParameterValueError
  from pymc.testing import assert_moment_is_expected
label_desc: Use image node_id 7 for calling a global function with example usage: test_truncation_discrete_random(op_type, lower, upper) without return types