2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-05-11 05:45:08 +01:00
Files
troggle/core/position_tests.py
T

80 lines
2.9 KiB
Python

import xml.etree.ElementTree as ET
from position_utils import which_area # file-type import, not module type.
def run_limit_tests(which_area_func):
# Boundary limits derived from GPX data
west_limit = 13.72476763 # 1626-22 [cite: 1]
east_limit = 13.86031535 # 1626-256 [cite: 3]
print("Running Border Logic Tests...")
# 1. Invalid point to the West
res, area = which_area_func(47.69, west_limit - 0.01)
print(f"Test West: Expected (False, 'None'), Got ({res}, '{area}')")
# 2. Invalid point to the East
res, area = which_area_func(47.70, east_limit + 0.01)
print(f"Test East: Expected (False, 'None'), Got ({res}, '{area}')")
def generate_test_data():
offset = 0.0005
# 6 base points extracted from the track to ensure we cover the whole E/W span
# Coordinates from source GPX
base_coords = [
(47.69048595, 13.72476763 + 2* offset), # Far West (1626-22)
(47.68532296, 13.73512238), # Monotonic section 1 (1626-13)
(47.67441976, 13.76998479), # Central dip (1626-308)
(47.68909077, 13.79091566), # Rising section (1626-294)
(47.70536617, 13.82402883), # Northern peak (1626-278)
(47.70002466, 13.86031535 - 2* offset) # Far East (1626-256)
]
test_points = []
for lat, lon in base_coords:
# Generate North point (Area 1626)
test_points.append({'lat': lat + offset, 'lon': lon + offset, 'area': '1626', 'desc': 'North_Test'})
# Generate South point (Area 1623)
test_points.append({'lat': lat - offset, 'lon': lon - offset, 'area': '1623', 'desc': 'South_Test'})
return test_points
def export_test_gpx(test_points, filename="test_points.gpx"):
gpx = ET.Element("gpx", version="1.1", creator="Python Script",
xmlns="http://www.topografix.com/GPX/1/1")
for pt in test_points:
wpt = ET.SubElement(gpx, "wpt", lat=str(pt['lat']), lon=str(pt['lon']))
name = ET.SubElement(wpt, "name")
name.text = f"{pt['area']}_{pt['desc']}"
desc = ET.SubElement(wpt, "desc")
desc.text = f"Expected Area: {pt['area']}"
tree = ET.ElementTree(gpx)
tree.write(filename, encoding="utf-8", xml_declaration=True)
print(f"Successfully created {filename} with 12 test waypoints.")
def run_12_point_test(which_area_func):
points = generate_test_data()
export_test_gpx(points)
passed = 0
print(f"{'Lat':<12} | {'Lon':<12} | {'Expected':<10} | {'Result'}")
print("-" * 55)
for pt in points:
valid, area = which_area_func(pt['lat'], pt['lon'])
status = "PASS" if (valid and area == pt['area']) else "FAIL"
if status == "PASS": passed += 1
print(f"{pt['lat']:<12.6f} | {pt['lon']:<12.6f} | {pt['area']:<10} | {status}")
print(f"\nSummary: {passed}/12 points passed.")
# Uncomment to run:
run_limit_tests(which_area)
run_12_point_test(which_area)