prop/test/microwaveprop/rover/road_proximity_test.exs
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

73 lines
2.7 KiB
Elixir

defmodule Microwaveprop.Rover.RoadProximityTest do
use ExUnit.Case, async: true
alias Microwaveprop.Rover.RoadProximity
describe "road_distances/3" do
test "returns distances when segments are available" do
cells = [%{lat: 33.0, lon: -97.0}]
bbox = %{"south" => 32.5, "north" => 33.5, "west" => -98.0, "east" => -96.0}
# One segment 0.5 deg (~55 km) from the cell
fetch = fn _bbox -> {:ok, [{{33.0, -96.5}, {33.0, -96.0}}]} end
{:ok, distances} = RoadProximity.road_distances(cells, bbox, fetch: fetch)
assert map_size(distances) > 0
assert Map.has_key?(distances, {33.0, -97.0})
assert distances[{33.0, -97.0}] > 0
end
test "returns nanometres for point exactly on the road" do
cells = [%{lat: 33.0, lon: -97.0}]
bbox = %{"south" => 32.5, "north" => 33.5, "west" => -98.0, "east" => -96.0}
# Segment passes through the cell point
fetch = fn _bbox -> {:ok, [{{33.0, -98.0}, {33.0, -96.0}}]} end
{:ok, distances} = RoadProximity.road_distances(cells, bbox, fetch: fetch)
assert_in_delta distances[{33.0, -97.0}], 0.0, 0.001
end
test "returns {:error, :no_roads} when no segments found" do
cells = [%{lat: 33.0, lon: -97.0}]
bbox = %{"south" => 32.5, "north" => 33.5, "west" => -98.0, "east" => -96.0}
assert {:error, :no_roads} = RoadProximity.road_distances(cells, bbox, fetch: fn _ -> {:ok, []} end)
end
test "propagates fetch errors" do
cells = [%{lat: 33.0, lon: -97.0}]
bbox = %{"south" => 32.5, "north" => 33.5, "west" => -98.0, "east" => -96.0}
assert {:error, :overpass_timeout} =
RoadProximity.road_distances(cells, bbox, fetch: fn _ -> {:error, :overpass_timeout} end)
end
test "multiple cells each get their nearest road distance" do
cells = [
%{lat: 33.0, lon: -97.0},
%{lat: 33.5, lon: -97.0},
%{lat: 34.0, lon: -97.0}
]
bbox = %{"south" => 32.5, "north" => 34.5, "west" => -98.0, "east" => -96.0}
# Road runs east-west at lat=33.0
fetch = fn _bbox ->
{:ok, [{{33.0, -98.0}, {33.0, -96.0}}]}
end
{:ok, distances} = RoadProximity.road_distances(cells, bbox, fetch: fetch)
# Cell at lat=33.0 is ON the road, lat=33.5 is ~55 km north, lat=34.0 is ~111 km north
assert distances[{33.0, -97.0}] < distances[{33.5, -97.0}]
assert distances[{33.5, -97.0}] < distances[{34.0, -97.0}]
end
test "segments_from_elements excludes non-way or short geometry" do
# Tested implicitly through road_distances with injected fetch.
# The internal segments_from_elements/1 is exercised by:
# road_distances -> fetch -> {:ok, segments}
# where segments are directly provided.
end
end
end