83 lines
2.4 KiB
Elixir
83 lines
2.4 KiB
Elixir
defmodule Towerops.Coverages.BuildingsTest do
|
|
use Towerops.DataCase, async: false
|
|
|
|
alias Towerops.Coverages.Building
|
|
alias Towerops.Coverages.Buildings
|
|
|
|
describe "to_clutter/1" do
|
|
test "uses the recorded rooftop height when present" do
|
|
building = %Building{height_m: 12.0, geom: square_polygon(0.0, 0.0, 0.001)}
|
|
|
|
assert %{height_m: 12.0, coords: coords} = Buildings.to_clutter(building)
|
|
assert length(coords) == 5
|
|
end
|
|
|
|
test "falls back to the default height when no value is recorded" do
|
|
building = %Building{height_m: nil, geom: square_polygon(0.0, 0.0, 0.001)}
|
|
|
|
assert %{height_m: height} = Buildings.to_clutter(building)
|
|
assert height == Building.default_height_m()
|
|
end
|
|
|
|
test "returns empty coords for a building whose geom isn't a polygon" do
|
|
building = %Building{height_m: 10.0, geom: nil}
|
|
assert %{coords: []} = Buildings.to_clutter(building)
|
|
end
|
|
end
|
|
|
|
describe "for_bbox/1" do
|
|
test "returns clutter rows whose footprints intersect the bbox" do
|
|
inside =
|
|
Repo.insert!(%Building{
|
|
source: "test",
|
|
height_m: 7.5,
|
|
ms_footprint_id: "in-1",
|
|
geom: square_polygon(-97.74, 30.27, 0.0005)
|
|
})
|
|
|
|
_outside =
|
|
Repo.insert!(%Building{
|
|
source: "test",
|
|
height_m: 5.0,
|
|
ms_footprint_id: "out-1",
|
|
geom: square_polygon(-95.0, 28.0, 0.0005)
|
|
})
|
|
|
|
results = Buildings.for_bbox({-97.75, 30.26, -97.73, 30.28})
|
|
|
|
assert [clutter] = results
|
|
assert clutter.height_m == 7.5
|
|
assert clutter.coords != []
|
|
|
|
# Sanity check: outside row really exists in the table.
|
|
assert Repo.aggregate(Building, :count) == 2
|
|
assert Repo.get_by(Building, ms_footprint_id: inside.ms_footprint_id)
|
|
end
|
|
|
|
test "returns an empty list when the bbox lands in unpopulated territory" do
|
|
Repo.insert!(%Building{
|
|
source: "test",
|
|
height_m: 5.0,
|
|
ms_footprint_id: "anywhere",
|
|
geom: square_polygon(-97.74, 30.27, 0.0005)
|
|
})
|
|
|
|
assert [] = Buildings.for_bbox({0.0, 0.0, 0.001, 0.001})
|
|
end
|
|
end
|
|
|
|
defp square_polygon(lon, lat, side) do
|
|
%Geo.Polygon{
|
|
coordinates: [
|
|
[
|
|
{lon, lat},
|
|
{lon + side, lat},
|
|
{lon + side, lat + side},
|
|
{lon, lat + side},
|
|
{lon, lat}
|
|
]
|
|
],
|
|
srid: 4326
|
|
}
|
|
end
|
|
end
|