From 68992a0f3d634b45234932a7d9db3c9b467664f6 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Wed, 6 Dec 2023 11:03:38 +0100 Subject: [PATCH] Add a test if the coordinate systems are identical Checks if the property layer and the property grid use coordinates in the same way. --- tests/test_space.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_space.py b/tests/test_space.py index 0282b8f3f82..5243f1aa956 100644 --- a/tests/test_space.py +++ b/tests/test_space.py @@ -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