Files
lora_route_py/sim/tests/test_route_stability.py
sinlatansen d357a25076 只有hello包实现多跳,还没加入业务数据
具体的还要看opencode和gpt记录接着优化
2026-02-24 17:17:45 +08:00

56 lines
1.4 KiB
Python

"""
Test: Route Stability
Assert:
- route_change_rate < threshold
This verifies that routes stabilize after convergence.
"""
import pytest
import random
from sim.main import run_simulation
from sim import config
@pytest.fixture
def seed():
return 42
def test_route_stability(seed):
"""Test that route change rate is low after convergence."""
results = run_simulation(num_nodes=12, area_size=800, sim_time=200, seed=seed)
metrics = results["metrics"]
route_change_rate = metrics.get("route_change_rate", 0)
total_route_changes = metrics.get("route_changes", 0)
print(f"Route change rate: {route_change_rate}")
print(f"Total route changes: {total_route_changes}")
# After convergence, route changes should be minimal
# Allow some route changes during initial convergence
assert total_route_changes >= 0, "Route changes should be non-negative"
def test_route_stability_threshold(seed):
"""Test against specific threshold."""
results = run_simulation(num_nodes=12, area_size=800, sim_time=200, seed=seed)
metrics = results["metrics"]
route_change_rate = metrics.get("route_change_rate", 0)
print(f"Route change rate: {route_change_rate}")
# Threshold: less than 10 changes per second (very lenient)
threshold = 10.0
assert route_change_rate < threshold, (
f"Route unstable: {route_change_rate} > {threshold}"
)
if __name__ == "__main__":
pytest.main([__file__, "-v", "-s"])