Skip to content

Commit a74b120

Browse files
committed
Add tests for agent removal and model agent_types property
1 parent 542a9b8 commit a74b120

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/test_agent.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from mesa.agent import Agent
2+
from mesa.model import Model
3+
4+
5+
def test_agent_removal():
6+
class TestAgent(Agent):
7+
pass
8+
9+
model = Model()
10+
agent = TestAgent(model.next_id(), model)
11+
# Check if the agent is added
12+
assert agent in model.agents[type(agent)]
13+
14+
agent.remove()
15+
# Check if the agent is removed
16+
assert agent not in model.agents[type(agent)]

tests/test_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from mesa.agent import Agent
12
from mesa.model import Model
23

34

@@ -40,3 +41,13 @@ def test_reset_randomizer(newseed=42):
4041
assert model._seed == oldseed
4142
model.reset_randomizer(seed=newseed)
4243
assert model._seed == newseed
44+
45+
46+
def test_agent_types():
47+
class TestAgent(Agent):
48+
pass
49+
50+
model = Model()
51+
test_agent = TestAgent(model.next_id(), model)
52+
assert test_agent in model.agents[type(test_agent)]
53+
assert type(test_agent) in model.agent_types

0 commit comments

Comments
 (0)