code: def testSamplingWithterminalInTrajectory(self):
      replay_capacity = 10
      update_horizon = 3
      memory = circular_replay_buffer.ReplayBuffer(
          stack_size=1,
          replay_capacity=replay_capacity,
          batch_size=2,
          update_horizon=update_horizon,
          gamma=1.0,
      )
      for i in range(replay_capacity):
          memory.add(
              observation=np.full(
                  OBSERVATION_SHAPE, i, dtype=OBS_DTYPE
              ),
              action=i * 2,
              reward=i,
              terminal=1 if i == 3 else 0,
          )
      indices = [2, 3, 4]
      batch = memory.sample_transition_batch(
          batch_size=len(indices), indices=torch.tensor(indices)
      )
      # In commone shape, state is 2-D unless stack_size > 1.
      expected_states = np.array(
          [
              np.full(OBSERVATION_SHAPE, i, dtype=OBS_DTYPE)
              for i in indices
          ]
      )
      # The reward in the replay buffer will be (an asterisk marks the terminal
      # state):
      #   [0 1 2 3* 4 5 6 7 8 9]
      # Since we're setting the update_horizon to 3, the accumulated trajectory
      # reward starting at each of the replay buffer positions will be:
      #   [3 6 5 3 15 18 21 24]
      # Since indices = [2, 3, 4], our expected reward are [5, 3, 15].
      expected_reward = np.array([[5], [3], [15]])
      # Because update_horizon = 3, both indices 2 and 3 include terminal.
      expected_terminal = np.array([[1], [1], [0]]).astype(bool)
      npt.assert_array_equal(batch.state, expected_states)
      npt.assert_array_equal(
          batch.action, np.expand_dims(np.array(indices) * 2, axis=1)
      )
      npt.assert_array_equal(batch.reward, expected_reward)
      npt.assert_array_equal(batch.terminal, expected_terminal)
      npt.assert_array_equal(
          batch.indices, np.expand_dims(np.array(indices), 1)
      )
  
imports: import tempfile
  import unittest
  import numpy
  import numpy.testing
  import torch
  from reagent.replay_memory import circular_replay_buffer
label_desc: Use image node_id 10 for calling the ReplayBufferTest obj's underlying member method code with example usage: obj.testSamplingWithterminalInTrajectory() without return types