Skip to content

Commit d233a76

Browse files
committed
Unit test
1 parent c5ec3c3 commit d233a76

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import numpy as np
2+
import pytest
3+
from mpl_toolkits.basemap import Basemap
4+
5+
# Extracted testable version of the core plotting logic
6+
def compute_arc_points(m, lon1, lat1, lon2, lat2, arc_height_ratio=0.15):
7+
t = np.linspace(0, 1, 300)
8+
lons = lon1 + (lon2 - lon1) * t
9+
lats = lat1 + (lat2 - lat1) * t
10+
mid_lat = (lat1 + lat2) / 2
11+
arc_direction = -1 if mid_lat > 0 else 1
12+
arc_height = arc_height_ratio * abs(lat2 - lat1 + 1e-6)
13+
bulge = np.cos(np.pi * (t - 0.5))
14+
lats += arc_direction * arc_height * bulge
15+
lats = np.clip(lats, -85, 85)
16+
x, y = m(lons, lats)
17+
return x, y
18+
19+
# === Unit test ===
20+
def test_better_great_circle():
21+
m = Basemap(projection='merc',
22+
llcrnrlon=-180, urcrnrlon=180,
23+
llcrnrlat=-60, urcrnrlat=80,
24+
lat_ts=20, resolution='c')
25+
# Example input: Anchorage → Moscow
26+
x, y = compute_arc_points(m, -149.9003, 61.2181, 37.6173, 55.7558)
27+
28+
# Test: All values are finite
29+
assert np.all(np.isfinite(x)), "X coordinates contain non-finite values"
30+
assert np.all(np.isfinite(y)), "Y coordinates contain non-finite values"
31+
32+
# Test: Array has expected length
33+
assert len(x) == 300 and len(y) == 300, "Coordinate arrays are incorrect length"
34+
35+
# Test: Latitude transformation is within Mercator-safe bounds
36+
_, test_lats = m(x, y, inverse=True)
37+
assert np.all((test_lats >= -85) & (test_lats <= 85)), "Some latitudes are out of bounds"

0 commit comments

Comments
 (0)