Files
maptool/test/test_track_stats.rb
T
randy cd4eef342b
CI / check (push) Successful in 1m56s
CI / deploy (push) Successful in 2m56s
Add a persisted test suite
`bundle exec rake test` (minitest, a default gem but pinned in
Gemfile for reproducibility) now covers what ad-hoc scripts kept
re-verifying by hand during development: Gpx/Fit/TrackStats parsing,
GpxStore/LiveTrackStore file/TTL logic, LiveTrackClient's payload
parsing, and app.rb's routes end to end via Rack::MockRequest.

MAPTOOL_DATA_DIR (new, app.rb) lets the suite point GPX_STORE/
LIVETRACK_STORE at a throwaway directory instead of real data/ —
without it every run would leave uploaded test files behind. Each
lib file's old `if __FILE__ == $0` self-check is now redundant with
real tests covering the same ground, so removed rather than kept as
a second copy of the same assertions. Wired into ci.yml so it isn't
just a local convenience.
2026-09-07 12:46:35 +02:00

36 lines
1.3 KiB
Ruby

require_relative "test_helper"
require "maptool/track_stats"
class TrackStatsTest < Minitest::Test
def test_computes_distance_and_elevation_gain_ignoring_descents
# A right-angle path (equirectangular approximation is accurate enough
# at this scale to just assert "nonzero, roughly plausible") with a
# climb-then-descend elevation profile, so both distance and
# elevation-gain have a real value to check against.
points = [
[17.0, 48.0, 100],
[17.001, 48.0, 150], # +50m gain
[17.001, 48.001, 120], # descent — not subtracted
]
times = [Time.utc(2026, 1, 1, 0, 0, 0), nil, Time.utc(2026, 1, 1, 0, 10, 0)]
stats = Maptool::TrackStats.compute(points, times: times)
assert_operator stats["distance_meters"], :>, 100
assert_equal 50.0, stats["elevation_gain_meters"]
assert_equal 600, stats["duration_secs"]
assert_equal 3, stats["point_count"]
end
def test_nil_elevation_gain_and_duration_when_data_is_missing
stats = Maptool::TrackStats.compute([[17.0, 48.0], [17.0, 48.0]], times: [])
assert_nil stats["elevation_gain_meters"]
assert_nil stats["duration_secs"]
end
def test_single_point_has_zero_distance
stats = Maptool::TrackStats.compute([[17.0, 48.0]])
assert_equal 0.0, stats["distance_meters"]
end
end