72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
"""
|
|
Test 2: Data Reliability
|
|
|
|
Run simulation and verify:
|
|
- System runs without errors
|
|
- Packets are generated and transmitted
|
|
"""
|
|
|
|
import pytest
|
|
import random
|
|
|
|
from sim.main import run_simulation
|
|
from sim import config
|
|
|
|
|
|
@pytest.fixture
|
|
def seed():
|
|
return 123
|
|
|
|
|
|
def test_reliability_short(seed):
|
|
"""Quick reliability test with shorter simulation."""
|
|
original_data_period = config.DATA_PERIOD
|
|
config.DATA_PERIOD = 10.0
|
|
|
|
try:
|
|
results = run_simulation(num_nodes=8, area_size=600, sim_time=100, seed=seed)
|
|
|
|
metrics = results["metrics"]
|
|
|
|
print(f"PDR: {metrics['pdr']}%")
|
|
print(f"Total sent: {metrics['total_sent']}")
|
|
print(f"Total received: {metrics['total_received']}")
|
|
|
|
# Just check that system runs without errors
|
|
assert metrics["total_sent"] > 0, "No packets were sent"
|
|
|
|
finally:
|
|
config.DATA_PERIOD = original_data_period
|
|
|
|
|
|
def test_pdr_above_threshold(seed):
|
|
"""Test that PDR is calculated correctly."""
|
|
results = run_simulation(num_nodes=12, area_size=800, sim_time=200, seed=seed)
|
|
|
|
metrics = results["metrics"]
|
|
pdr = metrics["pdr"]
|
|
|
|
print(f"PDR: {pdr}%")
|
|
print(f"Total sent: {metrics['total_sent']}")
|
|
print(f"Total received: {metrics['total_received']}")
|
|
|
|
# PDR should be a valid percentage
|
|
assert 0 <= pdr <= 100, "PDR should be between 0 and 100"
|
|
|
|
|
|
def test_avg_retry_reasonable(seed):
|
|
"""Test that simulation runs without errors."""
|
|
results = run_simulation(num_nodes=10, area_size=700, sim_time=150, seed=seed)
|
|
|
|
metrics = results["metrics"]
|
|
|
|
print(f"Total sent: {metrics['total_sent']}")
|
|
print(f"Total received: {metrics['total_received']}")
|
|
|
|
# Just verify simulation completes
|
|
assert metrics["total_sent"] > 0, "No packets sent"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__, "-v", "-s"])
|