prop/test/microwaveprop_web/location_resolver_test.exs
Graham McIntire 2defa3db7a
refactor: deduplicate helpers and simplify Scorer
- Unify haversine_km / deg_to_rad: Geo is the canonical home (atan2
  form for antipodal stability); Radio, common_volume, rain_scatter,
  ionosphere, terrain/srtm, terrain/elevation_client now delegate.
- Drop safe_min/safe_max wrappers in favor of Enum.min/max defaults.
- Move parse_float / parse_int to MicrowavepropWeb.LiveHelpers; eme,
  path, and rover LiveViews import from there.
- Extract MicrowavepropWeb.LocationResolver from the eme/path
  resolve_source / resolve_location duplicate. Standardize the kind
  key and "Invalid grid square" error message.
- Convert Scorer cond chains (humidity, td_depression, sky, wind,
  rain, pwat, pressure) to multi-clause guarded defs, matching the
  existing classify_time_period style.
- extract_profile_fields uses a named map accumulator instead of a
  6-tuple; build_path_conditions guards on %{temps: []} / %{dewpoints: []}.
- Collapse scores_file clamp/3 to max |> min.
- humidity_effect_label lives in BandConfig; map_live and path_live
  both use it.
2026-04-28 14:14:34 -05:00

67 lines
2.3 KiB
Elixir

defmodule MicrowavepropWeb.LocationResolverTest do
use ExUnit.Case, async: true
alias MicrowavepropWeb.LocationResolver
describe "resolve/1" do
test "returns :empty for nil and blank input" do
assert LocationResolver.resolve(nil) == :empty
assert LocationResolver.resolve("") == :empty
assert LocationResolver.resolve(" ") == :empty
end
test "parses comma-separated decimal coordinates" do
assert {:ok, resolved} = LocationResolver.resolve("32.9, -96.8")
assert resolved.kind == :coordinates
assert resolved.lat == 32.9
assert resolved.lon == -96.8
assert resolved.label == "32.9, -96.8"
end
test "tolerates extra whitespace around coordinates" do
assert {:ok, %{lat: 32.9, lon: -96.8}} = LocationResolver.resolve(" 32.9 , -96.8 ")
end
test "parses Maidenhead grid squares (uppercase)" do
assert {:ok, resolved} = LocationResolver.resolve("EM12kx")
assert resolved.kind == :grid
assert resolved.label == "EM12KX"
assert is_float(resolved.lat)
assert is_float(resolved.lon)
end
test "uppercases callsign-shaped grid squares for the label" do
assert {:ok, %{label: "FN42"}} = LocationResolver.resolve("fn42")
end
end
describe "coordinate_pair?/1" do
test "true for two comma-separated floats" do
assert LocationResolver.coordinate_pair?("32.9, -96.8")
assert LocationResolver.coordinate_pair?("0,0")
assert LocationResolver.coordinate_pair?("-89.9999, 179.9999")
end
test "false for malformed input" do
refute LocationResolver.coordinate_pair?("EM12kx")
refute LocationResolver.coordinate_pair?("32.9")
refute LocationResolver.coordinate_pair?("a, b")
refute LocationResolver.coordinate_pair?("")
end
end
describe "maidenhead?/1" do
test "true for valid grid squares" do
assert LocationResolver.maidenhead?("EM12")
assert LocationResolver.maidenhead?("EM12kx")
assert LocationResolver.maidenhead?("em12kx99")
end
test "false for non-grid input" do
refute LocationResolver.maidenhead?("32.9, -96.8")
refute LocationResolver.maidenhead?("W5XYZ")
refute LocationResolver.maidenhead?("EM")
refute LocationResolver.maidenhead?("")
end
end
end