aprs.me/test/aprsme/convert_test.exs
Graham McIntire 403300f696
test: broaden unit & property-test coverage (61.8% → 64.7%)
Adds ~800 new tests (incl. 27 StreamData properties) across 22 modules
that previously had little or no coverage. Highlights:

- Pure utility modules (LogSanitizer, PacketFieldWhitelist,
  PacketSanitizer, DeviceParser, CoordinateUtils, BoundsUtils,
  ParamUtils, Convert, WeatherUnits) get thorough unit + property
  coverage including UTF-8 truncation boundaries, antimeridian
  longitude wrap, Haversine symmetry, and unit-conversion inverses.
- JSON view modules (CallsignJSON, ErrorJSON, ChangesetJSON) verified
  for envelope shape and error templating.
- Plugs (HealthCheck, RateLimiter, ApiCSRF) exercised for happy-path
  and halt paths.
- GenServer modules (RegexCache, CleanupScheduler, DeploymentNotifier)
  tested without touching the supervised singleton where possible.
- Drops the orphaned map_live/map_helpers_test.exs whose module name
  collided with the new live/shared/coordinate_utils_test.exs.
2026-04-23 13:32:09 -05:00

100 lines
2.7 KiB
Elixir

defmodule Aprsme.ConvertTest do
use ExUnit.Case, async: true
use ExUnitProperties
alias Aprsme.Convert
describe "wind/3" do
test "converts ultimeter mph" do
assert Convert.wind(55, :ultimeter, :mph) == 3.417541556
end
test "zero stays zero" do
assert Convert.wind(0, :ultimeter, :mph) == 0.0
end
end
describe "temp/3" do
test "converts ultimeter f" do
assert Convert.temp(55, :ultimeter, :f) == 5.5
end
test "zero stays zero" do
assert Convert.temp(0, :ultimeter, :f) == 0.0
end
end
describe "speed/3" do
test "converts knots to mph" do
assert Convert.speed(55, :knots, :mph) == 63.29
end
test "zero knots is zero mph" do
assert Convert.speed(0, :knots, :mph) == 0.0
end
test "rounds to two decimal places" do
# 10 knots * 1.15077945 = 11.5077945, rounded = 11.51
assert Convert.speed(10, :knots, :mph) == 11.51
end
end
describe "f_to_c/1 and c_to_f/1" do
test "converts freezing point" do
assert Convert.f_to_c(32) == 0.0
assert Convert.c_to_f(0) == 32.0
end
test "converts boiling point" do
assert_in_delta Convert.f_to_c(212), 100.0, 0.0001
assert_in_delta Convert.c_to_f(100), 212.0, 0.0001
end
test "-40 is the same in both scales" do
assert_in_delta Convert.f_to_c(-40), -40.0, 0.0001
assert_in_delta Convert.c_to_f(-40), -40.0, 0.0001
end
property "f_to_c and c_to_f are inverses" do
check all(f <- float(min: -200.0, max: 300.0)) do
assert_in_delta Convert.c_to_f(Convert.f_to_c(f)), f, 0.0001
end
end
end
describe "mph_to_kph/1 and kph_to_mph/1" do
test "converts known value" do
assert_in_delta Convert.mph_to_kph(1), 1.60934, 0.0001
assert_in_delta Convert.kph_to_mph(1), 0.6214, 0.001
end
test "zero stays zero" do
assert Convert.mph_to_kph(0) == 0.0
assert Convert.kph_to_mph(0) == 0.0
end
property "mph_to_kph and kph_to_mph are inverses" do
check all(v <- float(min: 0.0, max: 1000.0)) do
assert_in_delta Convert.kph_to_mph(Convert.mph_to_kph(v)), v, 0.0001
end
end
end
describe "inches_to_mm/1 and mm_to_inches/1" do
test "one inch is 25.4 mm" do
assert Convert.inches_to_mm(1) == 25.4
assert_in_delta Convert.mm_to_inches(25.4), 1.0, 0.0001
end
test "zero stays zero" do
assert Convert.inches_to_mm(0) == 0.0
assert Convert.mm_to_inches(0) == 0.0
end
property "inches_to_mm and mm_to_inches are inverses" do
check all(v <- float(min: 0.0, max: 1000.0)) do
assert_in_delta Convert.mm_to_inches(Convert.inches_to_mm(v)), v, 0.0001
end
end
end
end