code: def testToNStepTransition(self):
      first = ts.StepType.FIRST
      mid = ts.StepType.MID
      last = ts.StepType.LAST
      gamma = 0.5
  
      # Define a batch size 1, 4-step trajectory.
      traj = trajectory.Trajectory(
          step_type=np.array([[first, mid, mid, last]]),
          next_step_type=np.array([[mid, mid, last, first]]),
          observation=np.array([[10.0, 20.0, 30.0, 40.0]]),
          action=np.array([[11.0, 22.0, 33.0, 44.0]]),
          # reward & discount values at step 3 is an invalid dummy reward.
          reward=np.array([[-1.0, 1.0, 2.0, 0.0]]),
          discount=np.array([[0.9, 0.95, 1.0, 0.0]]),
          policy_info=np.array([[10.0, 20.0, 30.0, 40.0]]),
      )
  
      transition = trajectory.to_n_step_transition(traj, gamma=gamma)
      self.assertIsInstance(transition, trajectory.Transition)
      time_steps, policy_steps, next_time_steps = transition
  
      self.assertAllEqual(time_steps.step_type, np.array([first]))
      self.assertAllEqual(time_steps.observation, np.array([10.0]))
      self.assertAllEqual(time_steps.reward, np.array([np.nan]))
      self.assertAllEqual(time_steps.discount, np.array([np.nan]))
  
      self.assertAllEqual(next_time_steps.step_type, np.array([last]))
      self.assertAllEqual(next_time_steps.observation, np.array([40.0]))
      # r0 + r1 * g * d0 + r2 * g * d0 * d1
      #   == -1.0 + 1.0*0.5*(0.9) + 2.0*(0.5**2)*(0.9*0.95)
      self.assertAllEqual(
          next_time_steps.reward,
          np.array(
              [-1.0 + 1.0 * gamma * 0.9 + 2.0 * gamma**2 * 0.9 * 0.95]
          ),
      )
      # gamma**2 * (d0 * d1 * d2)
      self.assertAllEqual(
          next_time_steps.discount,
          np.array([gamma**2 * (0.9 * 0.95 * 1.0)]),
      )
  
      self.assertAllEqual(policy_steps.action, np.array([11.0]))
      self.assertAllEqual(policy_steps.info, np.array([10.0]))
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import sys
  import numpy
  import tensorflow
  from tf_agents.drivers import dynamic_episode_driver
  from tf_agents.drivers import test_utils
  from tf_agents.environments import tf_py_environment
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.utils import test_utils
label_desc: Use image node_id 15 for calling the TrajectoryTest obj's underlying member method code with example usage: obj.testToNStepTransition() without return types