code: def test_get_recent_state_with_episode_boundaries():
      memory = SequentialMemory(
          3, window_length=2, ignore_episode_boundaries=False
      )
      obs_size = (3, 4)
  
      obs0 = np.random.random(obs_size)
      terminal0 = False
  
      obs1 = np.random.random(obs_size)
      terminal1 = False
  
      obs2 = np.random.random(obs_size)
      terminal2 = False
  
      obs3 = np.random.random(obs_size)
      terminal3 = True
  
      obs4 = np.random.random(obs_size)
      terminal4 = False
  
      obs5 = np.random.random(obs_size)
      terminal5 = True
  
      obs6 = np.random.random(obs_size)
      terminal6 = False
  
      state = np.array(memory.get_recent_state(obs0))
      assert state.shape == (2,) + obs_size
      assert np.allclose(state[0], 0.0)
      assert np.all(state[1] == obs0)
  
      # memory.append takes the current observation, the reward after taking an action and if
      # the *new* observation is terminal, thus `obs0` and `terminal1` is correct.
      memory.append(obs0, 0, 0.0, terminal1)
      state = np.array(memory.get_recent_state(obs1))
      assert state.shape == (2,) + obs_size
      assert np.all(state[0] == obs0)
      assert np.all(state[1] == obs1)
  
      memory.append(obs1, 0, 0.0, terminal2)
      state = np.array(memory.get_recent_state(obs2))
      assert state.shape == (2,) + obs_size
      assert np.all(state[0] == obs1)
      assert np.all(state[1] == obs2)
  
      memory.append(obs2, 0, 0.0, terminal3)
      state = np.array(memory.get_recent_state(obs3))
      assert state.shape == (2,) + obs_size
      assert np.all(state[0] == obs2)
      assert np.all(state[1] == obs3)
  
      memory.append(obs3, 0, 0.0, terminal4)
      state = np.array(memory.get_recent_state(obs4))
      assert state.shape == (2,) + obs_size
      assert np.all(state[0] == np.zeros(obs_size))
      assert np.all(state[1] == obs4)
  
      memory.append(obs4, 0, 0.0, terminal5)
      state = np.array(memory.get_recent_state(obs5))
      assert state.shape == (2,) + obs_size
      assert np.all(state[0] == obs4)
      assert np.all(state[1] == obs5)
  
      memory.append(obs5, 0, 0.0, terminal6)
      state = np.array(memory.get_recent_state(obs6))
      assert state.shape == (2,) + obs_size
      assert np.all(state[0] == np.zeros(obs_size))
      assert np.all(state[1] == obs6)
  
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 2 for calling a global function with example usage: test_get_recent_state_with_episode_boundaries() without return types