code: def test_ring_buffer():
      def assert_elements(b, ref):
          assert len(b) == len(ref)
          for idx in range(b.maxlen):
              if idx >= len(ref):
                  with pytest.raises(KeyError):
                      b[idx]
              else:
                  assert b[idx] == ref[idx]
  
      b = RingBuffer(5)
  
      # Fill buffer.
      assert_elements(b, [])
      b.append(1)
      assert_elements(b, [1])
      b.append(2)
      assert_elements(b, [1, 2])
      b.append(3)
      assert_elements(b, [1, 2, 3])
      b.append(4)
      assert_elements(b, [1, 2, 3, 4])
      b.append(5)
      assert_elements(b, [1, 2, 3, 4, 5])
  
      # Add couple more items with buffer at limit.
      b.append(6)
      assert_elements(b, [2, 3, 4, 5, 6])
      b.append(7)
      assert_elements(b, [3, 4, 5, 6, 7])
      b.append(8)
      assert_elements(b, [4, 5, 6, 7, 8])
  
file_path: keras-rl/tests/rl/test_memory.py
imports: from __future__ import division
  import pytest
  import numpy
  from numpy.testing import assert_allclose
  from rl.memory import SequentialMemory, RingBuffer
label_desc: Use image node_id 1 for calling a global function with example usage: test_ring_buffer() without return types