def test_setAgentEnvironment(self):
     env = TwoDimensionalEnvironment(2, 2)
     env.set_feature(0, 0, "foo")
     agent = Agent()
     agent.set_env(env, 0, 1)
     self.assertEqual(agent.get_feature(Direction.UP),
                      "foo")  # above him should be foo
Example #2
0
 def test_moveAgent(self):
     env = TwoDimensionalEnvironment(1, 2)
     env.set_feature(0, 0, "foo")
     env.set_feature(0, 1, "bar")
     agent = Agent()
     agent.set_env(env, 0, 0)
     self.assertEqual(agent.get_feature(), "foo")
     agent.move(0, 1)
     self.assertEqual(agent.get_feature(), "bar")
Example #3
0
 def test_allFeaturesAreInitiallyNone(self):
     w = 5
     h = 10
     count = 0
     env = TwoDimensionalEnvironment(w, h)
     for x in range(w):
         for y in range(h):
             f = env.get_feature(x, y)
             self.assertIsNone(f)
             count += 1
     self.assertEqual(w * h, count)
Example #4
0
    def test_bigObject(self):
        env = TwoDimensionalEnvironment(5, 5)

        self.assertRaises(
            RuntimeError,
            env.load_object,
            (  # object is bigger than environment
                ("---\n"
                 "name: Object A\n"
                 "width: 20\n"
                 "height: 20\n"
                 "features:\n"
                 "  - { x: 3, y: 3, data: A }\n"
                 "  - { x: 4, y: 3, data: A }\n"
                 "  - { x: 3, y: 4, data: B }\n")),
        )

        self.assertRaises(
            RuntimeError,
            env.load_object,
            (  # object contains invalid feature
                ("---\n"
                 "name: Object A\n"
                 "width: 5\n"
                 "height: 5\n"
                 "features:\n"
                 "  - { x: 3, y: 3, data: A }\n"
                 "  - { x: 4, y: 3, data: A }\n"
                 "  - { x: 99, y: 4, data: B }\n")),
        )
    def test_checkBorders(self):
        env = TwoDimensionalEnvironment(2, 2)

        agent = Agent()
        agent.set_env(env, 0, 0)
        self.assertEqual(agent.get_feature(Direction.UP), None)
        self.assertEqual(agent.get_feature(Direction.LEFT), None)

        agent.move(1, 1)
        self.assertEqual(agent.get_feature(Direction.DOWN), None)
        self.assertEqual(agent.get_feature(Direction.RIGHT), None)
Example #6
0
 def test_load_features(self):
     env = TwoDimensionalEnvironment(28, 28)
     env.load_object(("---\n"
                      "name: Object A\n"
                      "width: 20\n"
                      "height: 20\n"
                      "features:\n"
                      "  - { x: 3, y: 3, data: A }\n"
                      "  - { x: 4, y: 3, data: A }\n"
                      "  - { x: 3, y: 4, data: B }\n"))
     self.assertEqual(env.get_feature(3, 3), "A")
     self.assertEqual(env.get_feature(4, 3), "A")
     self.assertEqual(env.get_feature(3, 4), "B")
    def test_moveAgent(self):
        env = TwoDimensionalEnvironment(3, 3)
        env.set_feature(0, 0, "foo1")
        env.set_feature(0, 1, "foo2")
        env.set_feature(2, 1, "foo3")
        env.set_feature(1, 2, "foo4")

        agent = Agent()
        agent.set_env(env, 0, 1)
        self.assertEqual(agent.get_feature(Direction.UP), "foo1")
        agent.move(1, 1)
        self.assertEqual(agent.get_feature(Direction.LEFT), "foo2")
        self.assertEqual(agent.get_feature(Direction.RIGHT), "foo3")
        self.assertEqual(agent.get_feature(Direction.DOWN), "foo4")
    def test_moveDirAgent(
            self):  # ensure that moveDir() behaves in consistent with move()
        env = TwoDimensionalEnvironment(3, 3)

        agent1 = Agent()
        agent1.set_env(env, 0, 1)

        agent2 = Agent()
        agent2.set_env(env, 0, 1)

        self.assertEqual(agent1.get_position(), agent2.get_position())
        agent1.move(0, 2)
        self.assertNotEqual(agent1.get_position(), agent2.get_position())
        agent2.moveDir(Direction.DOWN)
        self.assertEqual(agent1.get_position(), agent2.get_position())
        agent1.move(0, 1)
        agent2.moveDir(Direction.UP)
        self.assertEqual(agent1.get_position(), agent2.get_position())
        agent1.move(1, 1)
        agent2.moveDir(Direction.RIGHT)
        self.assertEqual(agent1.get_position(), agent2.get_position())
        agent1.move(0, 1)
        agent2.moveDir(Direction.LEFT)
        self.assertEqual(agent1.get_position(), agent2.get_position())
Example #9
0
 def test_setManyFeatures(self):
     env = TwoDimensionalEnvironment(1, 2)
     env.set_feature(0, 0, "foo")
     env.set_feature(0, 1, "bar")
     self.assertEqual(env.get_feature(0, 0), "foo")
     self.assertEqual(env.get_feature(0, 1), "bar")
Example #10
0
 def test_setOneFeature(self):
     env = TwoDimensionalEnvironment(1, 1)
     env.set_feature(0, 0, "foo")
     self.assertEqual(env.get_feature(0, 0), "foo")
Example #11
0
 def test_sizeMatchesInputDimensions(self):
     env = TwoDimensionalEnvironment(28, 28)
     self.assertEqual(env.size(), 784)
Example #12
0
 def test_setAgentEnvironment(self):
     env = TwoDimensionalEnvironment(1, 1)
     env.set_feature(0, 0, "foo")
     agent = Agent()
     agent.set_env(env, 0, 0)
     self.assertEqual(agent.get_feature(), "foo")