File size: 900 Bytes
1025a87 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from unittest.mock import patch
from socialdynamics.simulation import OpinionSimulation, SimulationConfig
from socialdynamics.visualization import influence_figure, network_figure
def test_large_network_visualization_avoids_spring_layout():
for n_agents in (500, 1000):
sim = OpinionSimulation(SimulationConfig(n_agents=n_agents, steps=1, seed=11))
with patch("networkx.spring_layout", side_effect=AssertionError("spring_layout called")):
fig = network_figure(sim)
assert len(fig.data) == 2
assert len(sim._layout_cache) == n_agents
def test_influence_map_supports_all_population_sizes():
for n_agents in (100, 500, 1000):
sim = OpinionSimulation(SimulationConfig(n_agents=n_agents, steps=2, seed=7))
sim.run()
fig = influence_figure(sim)
assert len(fig.data) == 1
assert len(fig.data[0].x) == n_agents
|