prop/test/microwaveprop/buildings/loader_test.exs
Graham McIntire e3d430f8c4
feat(weather): add duct cutoff band map layer
Show on /weather where the detected duct geometry traps each microwave
band. Overview mode bins cells by their lowest trapped frequency
(Bean & Dutton cutoff); band-picker mode masks cells whose duct doesn't
reach the selected band. Cutoff is pre-computed per cell in both
writers (Elixir derive + Rust derive_row reads best_duct_freq_ghz from
CellValues), persisted to ScalarFile, and shipped to the JS hook via
the existing binary cell pack. Also cleans up six pre-existing
length/1 credo warnings in unrelated test files.
2026-05-15 19:51:24 -05:00

65 lines
2 KiB
Elixir

defmodule Microwaveprop.Buildings.LoaderTest do
use ExUnit.Case, async: false
alias Microwaveprop.Buildings.Index
alias Microwaveprop.Buildings.Loader
setup do
Index.clear()
tmp = Path.join(System.tmp_dir!(), "buildings_cache_#{System.unique_integer([:positive])}")
prev = Application.get_env(:microwaveprop, :buildings_cache_dir)
Application.put_env(:microwaveprop, :buildings_cache_dir, tmp)
on_exit(fn ->
File.rm_rf(tmp)
if prev,
do: Application.put_env(:microwaveprop, :buildings_cache_dir, prev),
else: Application.delete_env(:microwaveprop, :buildings_cache_dir)
end)
:ok
end
describe "ensure_loaded/1" do
test "skips loading when quadkey is already loaded" do
Index.mark_loaded("023112330")
assert Loader.ensure_loaded("023112330") == :ok
end
test "marks quadkey as loaded when tile file doesn't exist" do
assert Loader.ensure_loaded("nonexistent_quadkey") == :ok
assert Index.loaded?("nonexistent_quadkey")
end
test "loads records from a real tile file" do
quadkey = "023112330"
cache_dir = Application.get_env(:microwaveprop, :buildings_cache_dir)
File.mkdir_p!(cache_dir)
geojsonl =
then(
~s|{"type": "Feature", "properties": {"height": 5.5}, "geometry": {"type": "Polygon", "coordinates": [[[-97.736, 32.221], [-97.736, 32.222], [-97.735, 32.222], [-97.735, 32.221], [-97.736, 32.221]]]}}|,
&:zlib.gzip/1
)
File.write!(Path.join(cache_dir, "#{quadkey}.csv.gz"), geojsonl)
assert Loader.ensure_loaded(quadkey) == :ok
assert Index.loaded?(quadkey)
assert Index.max_height_near(32.2215, -97.7355, 100) == 5.5
end
end
describe "ensure_loaded_for_bbox/1" do
test "returns list of quadkeys for the bbox" do
bbox = %{"south" => 32.5, "north" => 33.0, "west" => -97.5, "east" => -96.5}
keys = Loader.ensure_loaded_for_bbox(bbox)
assert is_list(keys)
assert keys != []
assert Enum.all?(keys, &is_binary/1)
end
end
end