code: def test_append_and_sample(self):
      capacity = self.capacity
      num_steps = self.num_steps
      rbuf = replay_buffers.PrioritizedReplayBuffer(
          capacity,
          normalize_by_max=self.normalize_by_max,
          error_max=5,
          num_steps=num_steps,
      )
  
      assert len(rbuf) == 0
  
      # Add one and sample one
      correct_item = collections.deque([], maxlen=num_steps)
      for _ in range(num_steps):
          trans1 = dict(
              state=0,
              action=1,
              reward=2,
              next_state=3,
              next_action=4,
              is_state_terminal=False,
          )
          correct_item.append(trans1)
          rbuf.append(**trans1)
      assert len(rbuf) == 1
      s1 = rbuf.sample(1)
      rbuf.update_errors([3.14])
      assert len(s1) == 1
      np.testing.assert_allclose(s1[0][0]["weight"], 1.0)
      del s1[0][0]["weight"]
      assert s1[0] == list(correct_item)
  
      # Add two and sample two, which must be unique
      correct_item2 = copy.deepcopy(correct_item)
      trans2 = dict(
          state=1,
          action=1,
          reward=2,
          next_state=3,
          next_action=4,
          is_state_terminal=True,
      )
      correct_item2.append(trans2)
      rbuf.append(**trans2)
      assert len(rbuf) == 2
      s2 = rbuf.sample(2)
      rbuf.update_errors([3.14, 2.71])
      assert len(s2) == 2
      del s2[0][0]["weight"]
      del s2[1][0]["weight"]
      if s2[0][num_steps - 1]["state"] == 1:
          assert s2[0] == list(correct_item2)
          assert s2[1] == list(correct_item)
      else:
          assert s2[0] == list(correct_item)
          assert s2[1] == list(correct_item2)
  
      # Weights should be different for different TD-errors
      s3 = rbuf.sample(2)
      assert not np.allclose(s3[0][0]["weight"], s3[1][0]["weight"])
  
      # Weights should be equal for different but clipped TD-errors
      rbuf.update_errors([5, 10])
      s3 = rbuf.sample(2)
      np.testing.assert_allclose(s3[0][0]["weight"], s3[1][0]["weight"])
  
      # Weights should be equal for the same TD-errors
      rbuf.update_errors([3.14, 3.14])
      s4 = rbuf.sample(2)
      np.testing.assert_allclose(s4[0][0]["weight"], s4[1][0]["weight"])
  
imports: import collections
  import copy
  import os
  import tempfile
  import unittest
  import numpy
  import pytest
  import torch
  from pfrl import replay_buffer, replay_buffers
label_desc: Use image node_id 2 for calling the TestPrioritizedReplayBuffer obj's underlying member method code with example usage: obj.test_append_and_sample() without return types