class TestHexGridTorus(TestBaseGrid): ''' Testing a hexagonal toroidal grid. ''' torus = True def setUp(self): ''' Create a test non-toroidal grid and populate it with Mock Agents ''' width = 3 height = 5 self.grid = HexGrid(width, height, torus=True) self.agents = [] counter = 0 for x in range(width): for y in range(height): if TEST_GRID[x][y] == 0: continue counter += 1 # Create and place the mock agent a = MockAgent(counter, None) self.agents.append(a) self.grid.place_agent(a, (x, y)) def test_neighbors(self): ''' Test the hexagonal neighborhood methods on the toroid. ''' neighborhood = self.grid.get_neighborhood((1, 1)) assert len(neighborhood) == 6 neighborhood = self.grid.get_neighborhood((1, 1), include_center=True) assert len(neighborhood) == 7 neighborhood = self.grid.get_neighborhood((0, 0)) assert len(neighborhood) == 6 neighborhood = self.grid.get_neighborhood((2, 4)) assert len(neighborhood) == 6
class TestHexGrid(unittest.TestCase): """ Testing a hexagonal grid. """ def setUp(self): """ Create a test non-toroidal grid and populate it with Mock Agents """ width = 3 height = 5 self.grid = HexGrid(width, height, torus=False) self.agents = [] counter = 0 for x in range(width): for y in range(height): if TEST_GRID[x][y] == 0: continue counter += 1 # Create and place the mock agent a = MockAgent(counter, None) self.agents.append(a) self.grid.place_agent(a, (x, y)) def test_neighbors(self): """ Test the hexagonal neighborhood methods on the non-toroid. """ neighborhood = self.grid.get_neighborhood((1, 1)) assert len(neighborhood) == 6 neighborhood = self.grid.get_neighborhood((0, 2)) assert len(neighborhood) == 4 neighborhood = self.grid.get_neighborhood((1, 0)) assert len(neighborhood) == 3 neighborhood = self.grid.get_neighborhood((1, 4)) assert len(neighborhood) == 5 neighborhood = self.grid.get_neighborhood((0, 4)) assert len(neighborhood) == 2 neighborhood = self.grid.get_neighborhood((0, 0)) assert len(neighborhood) == 3 neighborhood = self.grid.get_neighborhood((1, 1), include_center=True) assert len(neighborhood) == 7