Skip to content

Commit

Permalink
Add tests for agent removal and model agent_types property
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Dec 17, 2023
1 parent 542a9b8 commit a74b120
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from mesa.agent import Agent
from mesa.model import Model


def test_agent_removal():
class TestAgent(Agent):
pass

model = Model()
agent = TestAgent(model.next_id(), model)
# Check if the agent is added
assert agent in model.agents[type(agent)]

agent.remove()
# Check if the agent is removed
assert agent not in model.agents[type(agent)]
11 changes: 11 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from mesa.agent import Agent
from mesa.model import Model


Expand Down Expand Up @@ -40,3 +41,13 @@ def test_reset_randomizer(newseed=42):
assert model._seed == oldseed
model.reset_randomizer(seed=newseed)
assert model._seed == newseed


def test_agent_types():
class TestAgent(Agent):
pass

model = Model()
test_agent = TestAgent(model.next_id(), model)
assert test_agent in model.agents[type(test_agent)]
assert type(test_agent) in model.agent_types

0 comments on commit a74b120

Please sign in to comment.