require_relative "test_helper" require "maptool/trip_days" class TripDaysTest < Minitest::Test D = Maptool::TripDays # A drive: a point a minute from `start` (local time), `n` of them, going north. def drive(start, n, lat0 = 48.0) t0 = Time.new(*start).to_f (0...n).map { |i| [17.0, lat0 + i * 0.01, 100.0 + i, t0 + i * 60] } end def test_a_night_stood_cuts_a_day_and_a_night_drive_cuts_at_three points = drive([2026, 12, 1, 18, 0], 60) + drive([2026, 12, 2, 8, 0], 30, 49.0) # stood 13 h assert_equal [[60, "auto"]], D.cuts(points) night = drive([2026, 12, 1, 23, 0], 300) # through the night, no stop assert_equal [[240, "night"]], D.cuts(night) # 23:00 + 240 min = 03:00 end def test_cuts_by_hand_and_joined points = drive([2026, 12, 1, 10, 0], 60) + drive([2026, 12, 1, 20, 0], 10, 49.0) hand = points[30][3] - 20 # between two points: the day starts at the next one cuts = D.cuts(points, hand: [hand]) assert_equal [[30, "hand"], [60, "auto"]], cuts assert_equal [[30, "hand"]], D.cuts(points, hand: [hand], joined: [points[60][3]]) days = D.days(points, cuts) assert_equal [1, 2, 3], days.map { |d| d[:index] } assert_equal [0, 30, 60], days.map { |d| d[:from] } assert_equal "auto", days[1][:cut][:kind] assert_equal 9 * 3600 + 60, days[1][:cut][:stood_s] # from 10:59 to 20:00 assert_in_delta 29 * 60, days[0][:driving_s], 1 assert_nil days.last[:cut] end def test_gpx_has_a_track_per_piece_with_times_and_pauses points = drive([2026, 12, 1, 10, 0], 3) + drive([2026, 12, 1, 11, 0], 3, 48.1) gpx = D.gpx([["Day 1", points.first(3)], ["Day 2", points.last(3)]], D.pauses(points)) assert_equal 2, gpx.scan("").size assert_includes gpx, "" assert_includes gpx, "Stood 58 min" end end