Commits

Lars Yencken committed ec8df08

Add another test of wraparound for mdp.

Comments (0)

Files changed (1)

     def setUp(self):
         pass
 
-    #def test_single_row(self):
-        #reward = np.array([0.0,0.0,0.0,8.0])
-        #reward.reshape((1, 4))
-        #value = mdp.value_iteration(reward, gamma=0.5, eps=1e-5)
-        #expected = np.array([1.0, 2.0, 4.0, 8.0])
-        #expected.reshape((1, 4))
-        #assert abs(value - expected).mean() < 1e-5
-
     def test_square(self):
         reward = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]])
         expected = np.array(
         value = mdp.value_iteration(reward, torus=True, gamma=0.5, eps=1e-5)
         assert abs(value - expected).mean() < 1e-5, str(value)
 
+    def test_wraparound_2(self):
+        reward = np.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]])
+        expected = np.array([[4, 2, 2], [2, 1, 1], [2, 1, 1]],
+                dtype=np.float32) / 3.0
+        value = mdp.value_iteration(reward, torus=True, gamma=0.5, eps=1e-5)
+        assert abs(value - expected).mean() < 1e-5, str(value)
+
 def suite():
     return unittest.TestSuite([
             unittest.makeSuite(MDPPlaneTest),