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.
This commit is contained in:
1 parent
a3c31ace06
commit
cd4eef342b
19 files changed
+706
-174
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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
|
||||
Reference in new issue
Block a user