code: def test_n_step_malformed_terminateds(self):
      # Test bad input (trajectory has `terminateds` in middle).
      # Re-use same batch, but change terminateds.
      gamma = 1.0
      obs = np.arange(0, 7)
      actions = np.random.randint(-1, 3, size=(7,))
      rewards = [10.0, 0.0, 100.0, 50.0, 60.0, 10.0, 100.0]
      next_obs = np.arange(1, 8)
      batch = SampleBatch(
          {
              SampleBatch.OBS: obs,
              SampleBatch.ACTIONS: actions,
              SampleBatch.REWARDS: rewards,
              SampleBatch.TERMINATEDS: [
                  False,
                  False,
                  True,
                  False,
                  False,
                  False,
                  True,
              ],
              SampleBatch.TRUNCATEDS: [
                  False,
                  False,
                  False,
                  False,
                  False,
                  False,
                  False,
              ],
              SampleBatch.NEXT_OBS: next_obs,
          }
      )
      self.assertRaisesRegex(
          AssertionError,
          "Unexpected terminated\\|truncated in middle",
          lambda: adjust_nstep(5, gamma, batch),
      )
  
      batch = SampleBatch(
          {
              SampleBatch.OBS: obs,
              SampleBatch.ACTIONS: actions,
              SampleBatch.REWARDS: rewards,
              SampleBatch.TERMINATEDS: [
                  False,
                  False,
                  False,
                  False,
                  False,
                  False,
                  True,
              ],
              SampleBatch.TRUNCATEDS: [
                  False,
                  True,
                  False,
                  True,
                  False,
                  False,
                  False,
              ],
              SampleBatch.NEXT_OBS: next_obs,
          }
      )
      self.assertRaisesRegex(
          AssertionError,
          "Unexpected terminated\\|truncated in middle",
          lambda: adjust_nstep(5, gamma, batch),
      )
  
file_path: ray/python/ray/rllib/evaluation/tests/test_postprocessing.py
imports: import numpy
  import unittest
  import ray
  from ray.rllib.evaluation.postprocessing import adjust_nstep, discount_cumsum
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.test_utils import check
label_desc: Use image node_id 5 for calling the TestPostprocessing obj's underlying member method code with example usage: obj.test_n_step_malformed_terminateds() without return types