只有hello包实现多跳,还没加入业务数据
具体的还要看opencode和gpt记录接着优化
This commit is contained in:
55
sim/tests/test_route_stability.py
Normal file
55
sim/tests/test_route_stability.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
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"])
|
||||
Reference in New Issue
Block a user