prop/test/microwaveprop_web/live_helpers_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

49 lines
1.4 KiB
Elixir

defmodule MicrowavepropWeb.LiveHelpersTest do
use ExUnit.Case, async: true
alias MicrowavepropWeb.LiveHelpers
describe "parse_float/2" do
test "returns default for nil and empty string" do
assert LiveHelpers.parse_float(nil, 1.5) == 1.5
assert LiveHelpers.parse_float("", 1.5) == 1.5
end
test "parses well-formed float strings" do
assert LiveHelpers.parse_float("3.14", 0.0) == 3.14
assert LiveHelpers.parse_float("-2.5", 0.0) == -2.5
end
test "parses integer strings to a float" do
assert LiveHelpers.parse_float("42", 0.0) == 42.0
end
test "returns default on garbage input" do
assert LiveHelpers.parse_float("nope", 7.0) == 7.0
end
test "accepts numbers via to_string conversion" do
assert LiveHelpers.parse_float(2.5, 0.0) == 2.5
end
end
describe "parse_int/2" do
test "returns default for nil and empty string" do
assert LiveHelpers.parse_int(nil, 5) == 5
assert LiveHelpers.parse_int("", 5) == 5
end
test "parses integer strings" do
assert LiveHelpers.parse_int("42", 0) == 42
assert LiveHelpers.parse_int("-7", 0) == -7
end
test "returns default on garbage input" do
assert LiveHelpers.parse_int("nope", 9) == 9
end
test "accepts integers via to_string conversion" do
assert LiveHelpers.parse_int(42, 0) == 42
end
end
end