Major refactoring of RFCP backend: - Modular propagation models (8 models) - SharedMemoryManager for terrain data - ProcessPoolExecutor parallel processing - WebSocket progress streaming - Building filtering pipeline (351k → 15k) - 82 unit tests Performance: Standard preset 38s → 5s (7.6x speedup) Known issue: Detailed preset timeout (fix in 3.1.0)
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
"""
|
|
Unit tests for haversine distance calculations.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import numpy as np
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
from app.geometry.haversine import haversine_distance, haversine_batch, points_to_local_coords
|
|
|
|
|
|
class TestHaversineDistance:
|
|
def test_same_point_is_zero(self):
|
|
d = haversine_distance(50.45, 30.52, 50.45, 30.52)
|
|
assert abs(d) < 1.0
|
|
|
|
def test_known_distance(self):
|
|
# Kyiv to Kharkiv ≈ 410 km
|
|
d = haversine_distance(50.45, 30.52, 49.99, 36.23)
|
|
assert 400000 < d < 420000
|
|
|
|
def test_short_distance(self):
|
|
# ~111m for 0.001 degree lat
|
|
d = haversine_distance(50.0, 30.0, 50.001, 30.0)
|
|
assert 100 < d < 120
|
|
|
|
|
|
class TestHaversineBatch:
|
|
def test_single_point(self):
|
|
lats = np.array([50.001])
|
|
lons = np.array([30.0])
|
|
distances = haversine_batch(50.0, 30.0, lats, lons)
|
|
assert len(distances) == 1
|
|
assert 100 < distances[0] < 120
|
|
|
|
def test_multiple_points(self):
|
|
lats = np.array([50.001, 50.01, 50.1])
|
|
lons = np.array([30.0, 30.0, 30.0])
|
|
distances = haversine_batch(50.0, 30.0, lats, lons)
|
|
assert len(distances) == 3
|
|
# Should be monotonically increasing
|
|
assert distances[0] < distances[1] < distances[2]
|
|
|
|
|
|
class TestLocalCoords:
|
|
def test_same_point_is_origin(self):
|
|
x, y = points_to_local_coords(50.0, 30.0, np.array([50.0]), np.array([30.0]))
|
|
assert abs(x[0]) < 1.0
|
|
assert abs(y[0]) < 1.0
|
|
|
|
def test_north_is_positive_y(self):
|
|
x, y = points_to_local_coords(50.0, 30.0, np.array([50.001]), np.array([30.0]))
|
|
assert y[0] > 0
|
|
assert abs(x[0]) < 1.0
|
|
|
|
def test_east_is_positive_x(self):
|
|
x, y = points_to_local_coords(50.0, 30.0, np.array([50.0]), np.array([30.001]))
|
|
assert x[0] > 0
|
|
assert abs(y[0]) < 1.0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for cls in [TestHaversineDistance, TestHaversineBatch, TestLocalCoords]:
|
|
instance = cls()
|
|
for method_name in [m for m in dir(instance) if m.startswith("test_")]:
|
|
try:
|
|
getattr(instance, method_name)()
|
|
print(f" PASS {cls.__name__}.{method_name}")
|
|
except Exception as e:
|
|
print(f" FAIL {cls.__name__}.{method_name}: {e}")
|
|
|
|
print("\nAll tests completed.")
|