Skip to content

Commit

Permalink
tests: Add test to check if RandomActivation is not sequential
Browse files Browse the repository at this point in the history
Adds a test that checks if the RandomActivation doesn't trigger agents in a sequential order.

In theory this could give false positives (a test passing when it shouldn't, but that chance is around ~0.1^18).
  • Loading branch information
EwoutH committed Jan 26, 2024
1 parent 99b35fc commit a7a2c87
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@ def test_get_agent_keys(self):
agent_ids = {agent.unique_id for agent in model.agents}
assert all(entry in agent_ids for entry in keys)

def test_not_sequential(self):
model = MockModel(activation=RANDOM)
# Create 10 agents
for _ in range(10):
model.schedule.add(MockAgent(model.next_id(), model))
# Run 3 steps
for _ in range(3):
model.step()
# Filter out non-integer elements from the log
filtered_log = [item for item in model.log if isinstance(item, int)]

# Check that there are no 18 consecutive agents id's in the filtered log
total_agents = 10
assert not any(
all(
(filtered_log[(i + j) % total_agents] - filtered_log[i]) % total_agents
== j % total_agents
for j in range(18)
)
for i in range(len(filtered_log))
), f"Agents are activated sequentially:\n{filtered_log}"


class TestSimultaneousActivation(TestCase):
"""
Expand Down

0 comments on commit a7a2c87

Please sign in to comment.