Пример #1
0
    def test_moveright(self):
        env = sliding_env.SlidingEnv(3)

        # move
        env.setGrid([1, 2, 5, 3, 7, 0, 6, 8, 4])
        env.step(1)
        self.assertTrue(np.array_equal(env.obs, [1, 2, 5, 3, 7, 0, 6, 8, 4]))

        # no moves
        env.setGrid([1, 2, 7, 3, 5, 8, 0, 6, 4])
        env.step(1)
        self.assertTrue(np.array_equal(env.obs, [1, 2, 7, 3, 5, 8, 6, 0, 4]))
Пример #2
0
 def test_checkGrid(self):
     env = sliding_env.SlidingEnv(3)
     self.assertRaises(Exception, env.setGrid,
                       [1, 2, 3, 4, 5, 6, 7, 8])  # incorrect shape
     self.assertRaises(Exception, env.setGrid,
                       [1, 2, 3, 4, 5, 6, 7, 10, 0])  # incorrect checksum
     self.assertRaises(Exception, env.setGrid,
                       [1, 2, 3, 4, 5, 6, 7, 9, -1])  # incorrect numbers
     self.assertRaises(Exception, env.setGrid,
                       [1, 2, 3, 4, 5, 6, 7, 8, 0])  # sorted
     self.assertRaises(Exception, env.setGrid,
                       [1, 2, 3, 4, 5, 6, 7, 0, 8])  # not solvable
     try:
         env.setGrid, [1, 2, 3, 4, 5, 0, 7, 8, 6]
     except:
         self.fail("Grid should be fine but raise an error")
Пример #3
0
 def test_metric(self):
     env = sliding_env.SlidingEnv(3)
     env.setGrid([1, 2, 5, 3, 7, 0, 6, 8, 4])
     self.assertEqual(env.metric, 13)