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