class_docstr: Unit tests for TabularQLearning.
class_docstr_tok: ["Unit","tests","for","TabularQLearning","."]
code: def test_init(self):
      # Discrete observation space.
      action_space = spaces.Discrete(2)
      observation_space = spaces.Discrete(3)
      sut = TabularQLearning("", observation_space, action_space)
      self.assertEqual(sut._num_actions, 2)
      self.assertEqual(sut._num_states, 3)
      self.assertEqual(sut._shape_of_inputs, (3,))
      self.assertTrue(sut._discrete_observation_space)
      self.assertIsNone(sut._space_discretizer)
      self.assertIsNone(sut._preprocessor)
  
      # Discretize observation space to default resolution.
      observation_space = spaces.Box(0, 1, (2,))
      sut = TabularQLearning("", observation_space, action_space)
      self.assertEqual(sut._num_states, 100)
      self.assertEqual(sut._shape_of_inputs, (100,))
      self.assertTrue(sut._discrete_observation_space)
      self.assertIsNotNone(sut._space_discretizer)
      # Verify encoding of state
      self.assertEqual(sut._discretize_state_if_necessary([0, 0]), 0)
      self.assertEqual(sut._discretize_state_if_necessary([0.05, 0]), 0)
      self.assertEqual(
          sut._discretize_state_if_necessary([0.95, 0]), 90
      )
      self.assertEqual(sut._discretize_state_if_necessary([0, 0.05]), 0)
      self.assertEqual(sut._discretize_state_if_necessary([0, 0.95]), 9)
      self.assertEqual(
          sut._discretize_state_if_necessary([0.1, 0.2]), 12
      )
      self.assertEqual(sut._discretize_state_if_necessary([1, 1]), 99)
  
      # Unsupported observation space for tabular representation
      observation_space = spaces.MultiBinary(10)
      self.assertRaises(
          ValueError,
          TabularQLearning,
          "",
          observation_space,
          action_space,
      )
  
file_path: CNTK/bindings/python/cntk/contrib/deeprl/tests/tabular_qlearning_test.py
imports: import unittest
  import cntk.contrib.deeprl.tests.spaces
  import numpy
  from cntk.contrib.deeprl.agent.tabular_qlearning import TabularQLearning
label_desc: Use image node_id 1 for calling the TabularQLearningTest obj's underlying member method code with example usage: obj.test_init() without return types