Exemplo n.º 1
0
 def test_get_agent_at(self):
     """
     Test getting an agent from some locale.
     """
     space = Space("test space", exec_key=self.exec_key)
     # before adding agent, all cells are empty:
     self.assertEqual(space.get_agent_at(1, 1), None)
     for i in range(DEF_HEIGHT):
         spot = space.place_member(mbr=self.test_agent, xy=(i, i))
         whos_there = space.get_agent_at(i, i)
         self.assertEqual(whos_there, self.test_agent)
Exemplo n.º 2
0
 def test_place_member_xy(self):
     """
     Test placing an agent at a particular x, y spot.
     We will run this DEF_HEIGHT times, to test multiple
     possible placements.
     """
     space = Space("test space", exec_key=self.exec_key)
     for i in range(DEF_HEIGHT):
         spot = space.place_member(mbr=self.test_agent, xy=(i, i))
         if spot is not None:
             (x, y) = (self.test_agent.get_x(),
                       self.test_agent.get_y())
             self.assertEqual((x, y), (i, i))
Exemplo n.º 3
0
 def test_composite_exists_neighbor(self):
     space1 = Space("test space1", exec_key=self.exec_key)
     test_reg1 = Region(space=space1, center=(3,3), size=3)
     space1 += self.test_agent
     space1 += self.test_agent2
     space1.place_member(mbr=self.test_agent, xy=(0, 1))
     space1.place_member(mbr=self.test_agent2, xy=(1,2))
     space2 = Space("test space2", exec_key=self.exec_key)
     test_reg2 = Region(space=space2, center=(7,7), size=3)
     space2 += self.test_agent3
     space2 += self.test_agent4
     space2.place_member(mbr=self.test_agent3, xy=(8, 8))
     space2.place_member(mbr=self.test_agent4, xy=(6,5))
     test_set = {test_reg1, test_reg2}
     test_comp = CompositeRegion(test_set)
     self.assertTrue(test_comp.exists_neighbor())
Exemplo n.º 4
0
def create_space(exec_key):
    space = Space("test space", exec_key=exec_key)
    newton = create_newton()
    space += newton
    space += create_hardy()
    space += create_leibniz()
    return space, newton
Exemplo n.º 5
0
 def test_composite_contains(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg1 = Region(space,(0,3),(3,3),(0,0),(3,0))
     test_reg2 = Region(space,(4,10),(10,10),(4,4),(10,4))
     test_reg3 = Region(space,(8,13),(9,13),(8,12),(9,12))
     test_set = {test_reg1, test_reg2, test_reg3}
     test_comp = CompositeRegion(test_set) 
     self.assertTrue(test_comp.contains((5,5)))
     self.assertFalse(test_comp.contains((9,13)))
Exemplo n.º 6
0
def create_teeny_space(exec_key):
    """
    This space should be full!
    """
    space = Space("test space", 2, 2, exec_key=exec_key)
    space += create_newton()
    space += create_hardy()
    space += create_leibniz()
    space += create_ramanujan()
    return space
Exemplo n.º 7
0
 def test_composite_get_agents(self):
     """
     Does this composite region contain n agents?
     """
     space1 = Space("test space1", exec_key=self.exec_key)
     test_reg1 = Region(space=space1, center=(3,3), size=3)
     space1 += self.test_agent
     space1 += self.test_agent2
     space1.place_member(mbr=self.test_agent, xy=(2, 3))
     space1.place_member(mbr=self.test_agent2, xy=(3,4))
     space2 = Space("test space2", exec_key=self.exec_key)
     test_reg2 = Region(space=space2, center=(7,7), size=3)
     space2 += self.test_agent3
     space2 += self.test_agent4
     space2.place_member(mbr=self.test_agent3, xy=(8, 8))
     space2.place_member(mbr=self.test_agent4, xy=(6,6))
     test_set = {test_reg1, test_reg2}
     test_comp = CompositeRegion(test_set)
     self.assertTrue(len(test_comp.get_agents()) == 4)
Exemplo n.º 8
0
 def test_check_bounds(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg = Region(space,(0,3),(3,3),(0,0),(3,0))
     self.assertTrue(test_reg.NW == (0,3))
     self.assertTrue(test_reg.NE == (3,3))
     self.assertTrue(test_reg.SW == (0,0))
     self.assertTrue(test_reg.SE == (3,0))
     test_reg2 = Region(space,(0,5),(12,5),(0,0),(12,0))
     self.assertTrue(test_reg2.NW == (0,5))
     self.assertTrue(test_reg2.NE == (10,5))
     self.assertTrue(test_reg2.SW == (0,0))
     self.assertTrue(test_reg2.SE == (10,0))
Exemplo n.º 9
0
 def test_get_num_of_agents(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg = Region(space=space, center=(3,3), size=3)
     space += self.test_agent
     space += self.test_agent2
     space.place_member(mbr=self.test_agent, xy=(0, 1))
     space.place_member(mbr=self.test_agent2, xy=(9, 9))
     self.assertEqual(test_reg.get_num_of_agents(), 1)
Exemplo n.º 10
0
 def test_exists_neighbor(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg = Region(space, (0, 3), (3, 3), (0, 0), (3, 0))
     self.assertFalse(test_reg.exists_neighbor())
     space += self.test_agent
     space += self.test_agent2
     space.place_member(mbr=self.test_agent, xy=(0, 1))
     space.place_member(mbr=self.test_agent2, xy=(1, 2))
     self.assertTrue(test_reg.exists_neighbor())
Exemplo n.º 11
0
 def test_get_agents(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg = Region(space=space, center=(3, 3), size=3)
     space += self.test_agent
     space += self.test_agent2
     space.place_member(mbr=self.test_agent, xy=(0, 1))
     space.place_member(mbr=self.test_agent2, xy=(1, 2))
     agent_ls = []
     agent_ls.append(self.test_agent)
     agent_ls.append(self.test_agent2)
     self.assertTrue(test_reg.get_agents() == agent_ls)
Exemplo n.º 12
0
 def test_sub_reg(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg = Region(space=space, center=(3,3), size=5)
     space += self.test_agent
     space += self.test_agent2
     space += self.test_agent3
     space.place_member(mbr=self.test_agent, xy=(2, 2))
     space.place_member(mbr=self.test_agent2, xy=(1, 2))
     space.place_member(mbr=self.test_agent3, xy=(7, 7))
     test_reg.create_sub_reg(space=space, center=(3, 3), size=2)
     for region in test_reg.my_sub_regs:
         self.assertTrue(len(region.my_agents)==2)
Exemplo n.º 13
0
 def test_get_ratio(self):
     """
     Test ratio of agents passing certain predicates.
     """
     space = Space("test space", exec_key=self.exec_key)
     test_reg = Region(space,(0,7),(7,7),(0,0),(7,0))
     space += self.test_agent
     space += self.test_agent2
     space += self.test_agent3
     space += self.test_agent4
     space.place_member(mbr=self.test_agent, xy=(3, 3))
     space.place_member(mbr=self.test_agent2, xy=(3,4))
     space.place_member(mbr=self.test_agent3, xy=(4,4))
     space.place_member(mbr=self.test_agent4, xy=(5,5))
     self.assertTrue(test_reg.get_ratio(lambda agent: True) == 1)
     self.assertTrue(test_reg.get_ratio(lambda agent: False) == 0)
     self.assertTrue(test_reg.get_ratio(lambda agent: False,
                                        lambda agent: True) == 0)
     self.assertTrue(test_reg.get_ratio(lambda agent: True,
                                        lambda agent: False) == 1)
Exemplo n.º 14
0
 def test_check_out_bounds(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg = CircularRegion(space, center=(3,3), radius=2)
     self.assertTrue(test_reg.check_out_bounds((12,12)))
Exemplo n.º 15
0
    def test_get_vonneumann_hood(self):
        """
        Get von Neumann neighborhood.
        """
        space = Space("test space", exec_key=self.exec_key)
        space += self.test_agent
        space += self.test_agent2
        space += self.test_agent3
        space += self.test_agent4

        for i in range(REP_RAND_TESTS):
            space.place_member(mbr=self.test_agent, xy=(0, 0))
            space.place_member(mbr=self.test_agent2, xy=(0, 1))
            hood = space.get_vonneumann_hood(self.test_agent)
            self.assertTrue(self.test_agent2.name in hood)

            space.place_member(mbr=self.test_agent3, xy=(1, 0))
            hood = space.get_vonneumann_hood(self.test_agent)
            self.assertTrue(self.test_agent3.name in hood)

            space.place_member(mbr=self.test_agent4, xy=(0, DEF_HEIGHT))
            hood = space.get_vonneumann_hood(self.test_agent)
            self.assertTrue(self.test_agent4.name not in hood)
Exemplo n.º 16
0
 def test_region_factory(self):
     space = Space("test space", exec_key=self.exec_key)
     region_one = region_factory(space,(0,3),(3,3),(0,0),(3,0))
     region_two = region_factory(space,(0,3),(3,3),(0,0),(3,0))
     self.assertTrue(region_one is region_two)
Exemplo n.º 17
0
 def test_contains(self):
     space = Space("test space", exec_key=self.exec_key)
     test_reg = Region(space,(0,3),(3,3),(0,0),(3,0))
     self.assertTrue(test_reg.contains((0,0)))
     self.assertTrue(test_reg.contains((2,2)))
     self.assertFalse(test_reg.contains((3,3)))