code: def test_store_and_get(buffer: SingleEpisodeBuffer):
      # store single non terminal transition
      transition = Transition(
          state={"observation": np.array([1, 2, 3])},
          action=1,
          reward=1,
          game_over=False,
      )
      buffer.store(transition)
      assert buffer.length() == 1
      assert buffer.num_complete_episodes() == 0
      assert buffer.num_transitions_in_complete_episodes() == 0
      assert buffer.num_transitions() == 1
  
      # get the single stored transition
      episode = buffer.get(0)
      assert episode.length() == 1
      assert (
          episode.get_first_transition() is transition
      )  # check addresses are the same
      assert (
          episode.get_last_transition() is transition
      )  # check addresses are the same
  
      # store single terminal transition
      transition = Transition(
          state={"observation": np.array([1, 2, 3])},
          action=1,
          reward=1,
          game_over=True,
      )
      buffer.store(transition)
      assert buffer.length() == 1
      assert buffer.num_complete_episodes() == 1
      assert buffer.num_transitions_in_complete_episodes() == 2
  
      # check that the episode is valid
      episode = buffer.get(0)
      assert episode.length() == 2
      assert (
          episode.get_transition(0).n_step_discounted_rewards
          == 1 + 0.99
      )
      assert episode.get_transition(1).n_step_discounted_rewards == 1
      assert buffer.mean_reward() == 1
  
      # only one episode in the replay buffer
      episode = buffer.get(1)
      assert episode is None
  
      # adding transitions after the first episode was closed
      transition = Transition(
          state={"observation": np.array([1, 2, 3])},
          action=1,
          reward=0,
          game_over=False,
      )
      buffer.store(transition)
      assert buffer.length() == 1
      assert buffer.num_complete_episodes() == 0
      assert buffer.num_transitions_in_complete_episodes() == 0
  
      # still only one episode
      assert buffer.get(1) is None
      assert buffer.mean_reward() == 0
  
file_path: coach/rl_coach/tests/memories/test_single_episode_buffer.py
imports: import os
  import sys
  import pytest
  import numpy
  from rl_coach.core_types import Transition
  from rl_coach.memories.episodic.single_episode_buffer import SingleEpisodeBuffer
label_desc: Use image node_id 2 for calling a global function with example usage: test_store_and_get(buffer) without return types