prop/test/microwaveprop/buildings/index_test.exs
Graham McIntire 58f4a7714b
test: add Mox deps + SnmpClient poll/3 tests, RoadProximity, Buildings.Loader
- Add {:mox, "~> 1.0", only: :test} to deps
- Commercial.SnmpClient: injectable snmp_runner for poll/3 tests (62→92%)
- Rover.RoadProximity: pure road_distances/3 tests with injectable fetch (37→82%)
- Buildings.Loader: ensure_loaded/1 with real tile file + quadkey tests (69→100%)
- Buildings.Index: records_near, mark_loaded, loaded? tests (72→96%)

Coverage: 77.96% → 78.93% (+0.97%)
2026-05-07 13:36:22 -05:00

64 lines
2.1 KiB
Elixir

defmodule Microwaveprop.Buildings.IndexTest do
use ExUnit.Case, async: false
alias Microwaveprop.Buildings.Index
setup do
Index.clear()
:ok
end
test "max_height_near/3 returns 0 when no buildings have been indexed" do
assert Index.max_height_near(32.8, -97.0, 100) == 0.0
end
test "insert_records/1 then max_height_near/3 returns the tallest nearby height" do
Index.insert_records([
%{centroid_lat: 32.8000, centroid_lon: -97.0000, max_radius_m: 10.0, height_m: 8.0},
%{centroid_lat: 32.8001, centroid_lon: -97.0001, max_radius_m: 10.0, height_m: 25.0},
# Far away — should not be considered.
%{centroid_lat: 33.0, centroid_lon: -97.5, max_radius_m: 10.0, height_m: 100.0}
])
assert Index.max_height_near(32.8000, -97.0000, 50) == 25.0
end
test "max_height_near/3 returns 0 when buildings are outside the radius" do
Index.insert_records([
%{centroid_lat: 32.8500, centroid_lon: -97.0500, max_radius_m: 10.0, height_m: 50.0}
])
assert Index.max_height_near(32.8000, -97.0000, 100) == 0.0
end
test "records_near/3 returns matching records" do
Index.insert_records([
%{centroid_lat: 32.8000, centroid_lon: -97.0000, max_radius_m: 10.0, height_m: 8.0},
%{centroid_lat: 32.8001, centroid_lon: -97.0001, max_radius_m: 10.0, height_m: 25.0}
])
records = Index.records_near(32.8000, -97.0000, 50)
assert length(records) == 2
heights = Enum.map(records, & &1.height_m) |> Enum.sort()
assert heights == [8.0, 25.0]
end
test "records_near/3 returns empty list outside radius" do
Index.insert_records([
%{centroid_lat: 33.0, centroid_lon: -97.5, max_radius_m: 10.0, height_m: 50.0}
])
assert Index.records_near(32.8, -97.0, 100) == []
end
test "mark_loaded/1 and loaded?/1 track loaded quadkeys" do
refute Index.loaded?("023112330")
Index.mark_loaded("023112330")
assert Index.loaded?("023112330")
end
test "insert_records/1 handles empty list" do
Index.insert_records([])
assert Index.max_height_near(32.8, -97.0, 100) == 0.0
end
end