prop/test/microwaveprop/propagation/grid_score_test.exs
Graham McIntire 775dff4263
Add CONUS grid definition and propagation score schema
Define 0.125-degree CONUS grid (25-50N, 125-66W) for propagation
scoring and create propagation_scores table with composite unique
index on lat/lon/valid_time/band_mhz for upsert support.
2026-03-30 16:50:06 -05:00

84 lines
2.5 KiB
Elixir

defmodule Microwaveprop.Propagation.GridScoreTest do
use Microwaveprop.DataCase, async: true
alias Microwaveprop.Propagation.GridScore
@valid_attrs %{
lat: 32.875,
lon: -97.0,
valid_time: ~U[2026-03-28 18:00:00Z],
band_mhz: 10_000,
score: 72,
factors: %{
"humidity" => 85,
"time_of_day" => 60,
"td_depression" => 70,
"refractivity" => 55,
"sky" => 80,
"season" => 65,
"wind" => 50,
"rain" => 90,
"pressure" => 45
}
}
describe "changeset/2" do
test "valid attributes" do
changeset = GridScore.changeset(%GridScore{}, @valid_attrs)
assert changeset.valid?
end
test "requires all fields" do
changeset = GridScore.changeset(%GridScore{}, %{})
assert %{
lat: ["can't be blank"],
lon: ["can't be blank"],
valid_time: ["can't be blank"],
band_mhz: ["can't be blank"],
score: ["can't be blank"],
factors: ["can't be blank"]
} = errors_on(changeset)
end
test "persists to database" do
changeset = GridScore.changeset(%GridScore{}, @valid_attrs)
assert {:ok, score} = Repo.insert(changeset)
assert score.lat == 32.875
assert score.lon == -97.0
assert score.band_mhz == 10_000
assert score.score == 72
assert score.factors["humidity"] == 85
end
test "enforces unique lat + lon + valid_time + band_mhz" do
assert {:ok, _} =
%GridScore{} |> GridScore.changeset(@valid_attrs) |> Repo.insert()
assert {:error, changeset} =
%GridScore{} |> GridScore.changeset(@valid_attrs) |> Repo.insert()
assert %{lat: ["has already been taken"]} = errors_on(changeset)
end
test "allows same location at different times" do
assert {:ok, _} =
%GridScore{} |> GridScore.changeset(@valid_attrs) |> Repo.insert()
later_attrs = Map.put(@valid_attrs, :valid_time, ~U[2026-03-28 19:00:00Z])
assert {:ok, _} =
%GridScore{} |> GridScore.changeset(later_attrs) |> Repo.insert()
end
test "allows same location and time for different bands" do
assert {:ok, _} =
%GridScore{} |> GridScore.changeset(@valid_attrs) |> Repo.insert()
other_band_attrs = Map.put(@valid_attrs, :band_mhz, 24_000)
assert {:ok, _} =
%GridScore{} |> GridScore.changeset(other_band_attrs) |> Repo.insert()
end
end
end