prop/test/microwaveprop/rover/elevation_test.exs
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

81 lines
2.7 KiB
Elixir

defmodule Microwaveprop.Rover.ElevationTest do
use ExUnit.Case, async: false
alias Microwaveprop.Rover.Elevation
setup do
tmp = Path.join(System.tmp_dir!(), "rover_elev_#{System.unique_integer([:positive])}")
File.mkdir_p!(tmp)
prev = Application.get_env(:microwaveprop, :srtm_tiles_dir)
Application.put_env(:microwaveprop, :srtm_tiles_dir, tmp)
on_exit(fn ->
File.rm_rf(tmp)
if prev do
Application.put_env(:microwaveprop, :srtm_tiles_dir, prev)
else
Application.delete_env(:microwaveprop, :srtm_tiles_dir)
end
end)
:ok
end
describe "lookup_many/1" do
test "returns map keyed by {lat, lon}, nil values when no tiles available" do
points = [{33.0, -96.0}, {30.0, -97.0}]
result = Elevation.lookup_many(points)
assert map_size(result) == 2
assert Map.has_key?(result, {33.0, -96.0})
assert Map.has_key?(result, {30.0, -97.0})
assert result[{33.0, -96.0}] == nil
assert result[{30.0, -97.0}] == nil
end
test "empty list returns empty map" do
assert Elevation.lookup_many([]) == %{}
end
test "duplicate points are deduplicated before lookup" do
points = [{33.0, -96.0}, {33.0, -96.0}, {33.1, -97.0}]
result = Elevation.lookup_many(points)
assert map_size(result) == 2
end
test "points on different tiles each get an entry" do
points = [{45.0, -120.0}, {30.0, -90.0}]
result = Elevation.lookup_many(points)
assert map_size(result) == 2
assert result[{45.0, -120.0}] == nil
assert result[{30.0, -90.0}] == nil
end
test "reads elevation from a valid SRTM tile file" do
# SRTM tile at lat~0, lon~0 (tile N00E000.hgt) stores 3601x3601
# 16-bit big-endian signed integers. Write a minimal valid tile
# with known elevation at the first sample point.
tile_path = Path.join(Application.get_env(:microwaveprop, :srtm_tiles_dir), "N00E000.hgt")
elev_value = 1234
# Build enough binary to cover offset 0 (row=0, col=0 = first sample)
binary = <<elev_value::signed-big-integer-size(16)>>
File.write!(tile_path, binary)
# lat=0.9999, lon=0.0 -> row=0, col=0 -> offset=0
result = Elevation.lookup_many([{0.9999, 0.0}])
assert result[{0.9999, 0.0}] == elev_value
end
test "returns nil for SRTM void sentinel values (-32768)" do
tile_path = Path.join(Application.get_env(:microwaveprop, :srtm_tiles_dir), "N00E000.hgt")
# SRTM void sentinel is -32768
File.write!(tile_path, <<-32_768::signed-big-integer-size(16)>>)
result = Elevation.lookup_many([{0.9999, 0.0}])
assert result[{0.9999, 0.0}] == nil
end
end
end