defmodule Microwaveprop.Propagation.GridTest do use ExUnit.Case, async: true alias Microwaveprop.Propagation.Grid describe "conus_points/0" do test "generates grid at 0.125 degree resolution" do points = Grid.conus_points() assert length(points) > 5000 assert length(points) < 100_000 end test "all points within CONUS bounds" do Enum.each(Grid.conus_points(), fn {lat, lon} -> assert lat >= 25.0 and lat <= 50.0 assert lon >= -125.0 and lon <= -66.0 end) end test "points are on 0.125 degree grid" do Enum.each(Grid.conus_points(), fn {lat, lon} -> assert Float.round(lat * 8, 0) == lat * 8 assert Float.round(lon * 8, 0) == lon * 8 end) end test "first point is at SW corner" do [{lat, lon} | _] = Grid.conus_points() assert lat == 25.0 assert lon == -125.0 end test "last point is at NE corner" do points = Grid.conus_points() {lat, lon} = List.last(points) assert lat == 50.0 assert lon == -66.0 end end describe "step/0" do test "returns 0.125" do assert Grid.step() == 0.125 end end describe "bounds/0" do test "returns CONUS bounding box" do bounds = Grid.bounds() assert bounds.lat_min == 25.0 assert bounds.lat_max == 50.0 assert bounds.lon_min == -125.0 assert bounds.lon_max == -66.0 end end describe "wgrib2_grid_spec/0" do test "lon_start / lat_start match the bounding box SW corner" do spec = Grid.wgrib2_grid_spec() assert spec.lon_start == -125.0 assert spec.lat_start == 25.0 end test "grid step matches Grid.step/0 on both axes" do spec = Grid.wgrib2_grid_spec() assert spec.lon_step == Grid.step() assert spec.lat_step == Grid.step() end test "lon_count and lat_count span the full CONUS box inclusive" do spec = Grid.wgrib2_grid_spec() # (lon_max - lon_min) / step + 1 = (-66 - -125) / 0.125 + 1 = 473 assert spec.lon_count == 473 # (lat_max - lat_min) / step + 1 = (50 - 25) / 0.125 + 1 = 201 assert spec.lat_count == 201 end test "total cells in wgrib2_grid_spec matches conus_points length" do spec = Grid.wgrib2_grid_spec() points = Grid.conus_points() assert length(points) == spec.lon_count * spec.lat_count end end end