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 = records |> Enum.map(& &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