예제 #1
0
    def test_add_agent(self):
        locator = TorusLocator(2, 5)
        agent = DummyAgent()

        locator.add_agent(agent, (0, 1))

        self.assertIsNotNone(locator.get_allowed_moves(agent))
예제 #2
0
    def test_allowed_moves(self):
        locator = TorusLocator(5, 6)
        agent = DummyAgent()
        locator.add_agent(agent, (0, 0))
        locator.add_agent(DummyAgent(), (1, 1))

        self.assertEquals(locator.get_allowed_moves(agent),
                          {(0, 1), (0, 5), (1, 0), (1, 5), (4, 0), (4, 1), (4, 5)})
예제 #3
0
    def test_neighbourhood_radius(self):
        locator = TorusLocator(5, 6, 2)
        agent = DummyAgent()
        locator.add_agent(agent, (0, 0))

        self.assertEquals(locator.get_allowed_moves(agent),
                          {(0, 1), (0, 5), (1, 0), (1, 1), (1, 5), (4, 0), (4, 1), (4, 5), (0, 2), (1, 2), (2, 2),
                           (2, 1), (2, 0), (3, 0), (3, 1), (3, 2), (4, 2), (0, 4), (1, 4), (2, 4), (2, 5), (4, 4),
                           (3, 4), (3, 5)})
예제 #4
0
    def test_remove_agent(self):
        locator = TorusLocator(5, 6)
        agent = DummyAgent()
        locator.add_agent(agent, (0, 0))
        self.assertNotIn((0, 0), locator.get_empty_slots())

        locator.remove_agent(agent)

        self.assertIn((0, 0), locator.get_empty_slots())
예제 #5
0
    def test_remove_dead_agents(self):
        locator = TorusLocator(5, 6)
        a1 = DummyAgent()
        a2 = DummyAgent()
        locator.add_agent(a1, (0, 0))
        locator.add_agent(a2, (0, 1))

        self.assertEqual(a2, locator.get_neighbour(a1))
        a2.dead = True

        self.assertIsNone(locator.get_neighbour(a1))
예제 #6
0
    def test_neighbourhood(self):
        locator = TorusLocator(5, 6)
        a1 = DummyAgent()
        a2 = DummyAgent()
        a3 = DummyAgent()
        locator.add_agent(a1, (0, 0))
        locator.add_agent(a2, (0, 1))
        locator.add_agent(a3, (0, 3))

        self.assertEqual(a2, locator.get_neighbour(a1))
        self.assertFalse(a3 == locator.get_neighbour(a1))
        self.assertIsNone(locator.get_neighbour(a3))
예제 #7
0
    def test_get_empty_slots(self):
        locator = TorusLocator(2, 5)
        self.assertEqual(locator.get_empty_slots(), [(x, y) for x in range(2) for y in range(5)])

        locator.add_agent(DummyAgent(), (0, 1))
        self.assertFalse((0, 1) in locator.get_empty_slots())
예제 #8
0
 def test_should_not_add_when_full(self):
     locator = TorusLocator(1, 1)
     locator.add_agent(DummyAgent())
     locator.add_agent(DummyAgent())
예제 #9
0
 def test_should_not_add_to_occupied_cell(self):
     locator = TorusLocator(2, 5)
     locator.add_agent(DummyAgent(), (0, 1))
     locator.add_agent(DummyAgent(), (0, 1))
예제 #10
0
 def test_remove_dead(self):
     locator = TorusLocator(1, 1)
     agent = DummyAgent()
     locator.add_agent(agent, (0, 0))
     agent.dead = True
     locator.add_agent(DummyAgent(), (0, 0))