Skip to content

Commit

Permalink
Add a test if the coordinate systems are identical
Browse files Browse the repository at this point in the history
Checks if the property layer and the property grid use coordinates in the same way.
  • Loading branch information
EwoutH committed Dec 6, 2023
1 parent 377c552 commit 68992a0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,28 @@ def test_invalid_mode_in_move_to_extreme(self):
with self.assertRaises(ValueError):
self.grid.move_agent_to_extreme_value_cell(agent, "layer1", "invalid_mode")

# Test if coordinates means the same between the grid and the property layer
def test_property_layer_coordinates(self):
agent = MockAgent(0, self.grid)
correct_pos = (1, 8)
incorrect_pos = (8, 1)
self.grid.place_agent(agent, correct_pos)

# Simple check on layer 1: set by agent, check by layer
self.grid.properties["layer1"].set_cell(agent.pos, 2)
self.assertEqual(self.grid.properties["layer1"].data[agent.pos], 2)

# More complicated check on layer 2: set by layer, check by agent
self.grid.properties["layer2"].set_cell(correct_pos, 3)
self.grid.properties["layer2"].set_cell(incorrect_pos, 4)

correct_grid_value = self.grid.properties["layer2"].data[correct_pos]
incorrect_grid_value = self.grid.properties["layer2"].data[incorrect_pos]
agent_grid_value = self.grid.properties["layer2"].data[agent.pos]

self.assertEqual(correct_grid_value, agent_grid_value)
self.assertNotEqual(incorrect_grid_value, agent_grid_value)


class TestSingleNetworkGrid(unittest.TestCase):
GRAPH_SIZE = 10
Expand Down

0 comments on commit 68992a0

Please sign in to comment.