25 lines
1.1 KiB
Ruby
25 lines
1.1 KiB
Ruby
require_relative "test_helper"
|
|
require_relative "../lib/maptool/gnss_sim"
|
|
|
|
class GnssSimTest < Minitest::Test
|
|
# A 1 km route north, 36 km/h limit for the first half, untagged after.
|
|
class FixedRoute < Maptool::GnssSim
|
|
def random_route(_position)
|
|
{ geometry: { coordinates: [[17.0, 48.0], [17.0, 48.0 + 1000.0 / 111_320]] },
|
|
properties: { speed_limits: [[0.0, 40], [0.5, nil]] } }
|
|
end
|
|
end
|
|
|
|
def test_drives_the_route_at_its_limits_and_ends_at_its_end
|
|
fixes = []
|
|
sim = FixedRoute.new("http://valhalla", sleep: ->(_s) {})
|
|
last = sim.drive([17.0, 48.0]) { |fix| fixes << fix }
|
|
assert_in_delta 36 / 3.6, fixes.first[:speed], 0.01 # 90 % of 40
|
|
assert_in_delta 45 / 3.6, fixes.last[:speed], 0.01 # 90 % of an untagged road's 50
|
|
assert_in_delta 48.0 + 1000.0 / 111_320, fixes.last[:lat], 1e-9
|
|
assert_equal [17.0, 48.0 + 1000.0 / 111_320], last
|
|
assert fixes.each_cons(2).all? { |a, b| b[:lat] >= a[:lat] } # never backwards
|
|
assert_in_delta 1000 / (36 / 3.6) / 2 + 500 / (45 / 3.6), fixes.size, 3 # ~1 fix a second
|
|
end
|
|
end
|