code: def test_fit_observations():
      memory = SequentialMemory(
          100, window_length=2, ignore_episode_boundaries=False
      )
      agent = TestAgent(memory)
      env = TestEnv()
      agent.compile()
      agent.fit(env, 20, verbose=0)
  
      # Inspect memory to see if observations are correct.
      experiencies = memory.sample(batch_size=6, batch_idxs=range(2, 8))
  
      assert experiencies[0].reward == 0.4
      assert experiencies[0].action == 3
      assert_allclose(experiencies[0].state0, np.array([2, 3]))
      assert_allclose(experiencies[0].state1, np.array([3, 4]))
      assert experiencies[0].terminal1 is False
  
      assert experiencies[1].reward == 0.5
      assert experiencies[1].action == 4
      assert_allclose(experiencies[1].state0, np.array([3, 4]))
      assert_allclose(experiencies[1].state1, np.array([4, 5]))
      assert experiencies[1].terminal1 is False
  
      assert experiencies[2].reward == 0.6
      assert experiencies[2].action == 5
      assert_allclose(experiencies[2].state0, np.array([4, 5]))
      assert_allclose(experiencies[2].state1, np.array([5, 6]))
      assert experiencies[2].terminal1 is True
  
      # Experience 3 has been re-sampled since since state0 would be terminal in which case we
      # cannot really have a meaningful transition because the environment gets reset. We thus
      # just ensure that state0 is not terminal.
      assert not np.all(experiencies[3].state0 == np.array([5, 6]))
  
      assert experiencies[4].reward == 0.2
      assert experiencies[4].action == 1
      assert_allclose(experiencies[4].state0, np.array([0, 1]))
      assert_allclose(experiencies[4].state1, np.array([1, 2]))
      assert experiencies[4].terminal1 is False
  
      assert experiencies[5].reward == 0.3
      assert experiencies[5].action == 2
      assert_allclose(experiencies[5].state0, np.array([1, 2]))
      assert_allclose(experiencies[5].state1, np.array([2, 3]))
      assert experiencies[5].terminal1 is False
  
imports: from __future__ import division
  import pytest
  import numpy
  from numpy.testing import assert_allclose
  from rl.memory import SequentialMemory
  from rl.core import Agent, Env, Processor
label_desc: Use image node_id 1 for calling a global function with example usage: test_fit_observations() without return types