50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
"""
|
|
Test: Multihop Exists
|
|
|
|
Assert:
|
|
- max_hop >= 2
|
|
|
|
This verifies that multi-hop routing is actually being used.
|
|
"""
|
|
|
|
import pytest
|
|
import random
|
|
|
|
from sim.main import run_simulation
|
|
from sim import config
|
|
|
|
|
|
@pytest.fixture
|
|
def seed():
|
|
return 42
|
|
|
|
|
|
def test_multihop_exists(seed):
|
|
"""Test that multi-hop routing is formed (hop >= 2)."""
|
|
results = run_simulation(num_nodes=12, area_size=800, sim_time=200, seed=seed)
|
|
|
|
metrics = results["metrics"]
|
|
max_hop = metrics.get("max_hop", 0)
|
|
|
|
print(f"Max hop: {max_hop}")
|
|
print(f"Hop distribution: {metrics.get('hop_histogram', {})}")
|
|
|
|
assert max_hop >= 2, f"Multi-hop not formed: max_hop={max_hop}"
|
|
|
|
|
|
def test_multihop_with_hop_histogram(seed):
|
|
"""Test hop distribution shows multiple hops."""
|
|
results = run_simulation(num_nodes=12, area_size=800, sim_time=300, seed=seed)
|
|
|
|
metrics = results["metrics"]
|
|
hop_histogram = metrics.get("hop_histogram", {})
|
|
|
|
print(f"Hop histogram: {hop_histogram}")
|
|
|
|
# Should have at least 2 different hop counts
|
|
assert len(hop_histogram) >= 1, "No hop distribution data"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__, "-v", "-s"])
|