mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 19:01:15 +00:00
f7ad7aa5ab
Extract RouteValidator (aggregating validator), RoutePointGraphBuilder (point interpolation + sequence numbering), GeofenceGridCalculator (NW/SE region centers), and RouteResponseMapper (entity -> DTO; also used by GetRouteAsync, eliminating duplicate DTO assembly). CreateRouteAsync shrinks 184 -> 52 LOC of orchestration. RouteService.cs shrinks 295 -> 138 LOC overall. Validation aggregates all failures into a single ArgumentException (AC-2); single-violation messages preserved verbatim so existing RouteServiceTests pass unchanged. 28 new unit tests for the four helpers (112/112 unit tests, smoke green). Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.6 KiB
C#
86 lines
2.6 KiB
C#
using FluentAssertions;
|
|
using SatelliteProvider.Common.DTO;
|
|
using SatelliteProvider.Services.RouteManagement;
|
|
|
|
namespace SatelliteProvider.Tests;
|
|
|
|
public class GeofenceGridCalculatorTests
|
|
{
|
|
[Fact]
|
|
public void GenerateRegions_SmallPolygon_ReturnsAtLeastOneCenter()
|
|
{
|
|
var sut = new GeofenceGridCalculator();
|
|
var nw = new GeoPoint(48.280, 37.370);
|
|
var se = new GeoPoint(48.265, 37.395);
|
|
|
|
var regions = sut.GenerateRegions(nw, se, regionSizeMeters: 300);
|
|
|
|
regions.Should().NotBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateRegions_AllCentersInsidePolygon()
|
|
{
|
|
var sut = new GeofenceGridCalculator();
|
|
var nw = new GeoPoint(48.280, 37.370);
|
|
var se = new GeoPoint(48.265, 37.395);
|
|
|
|
var regions = sut.GenerateRegions(nw, se, regionSizeMeters: 300);
|
|
|
|
regions.Should().OnlyContain(p =>
|
|
p.Lat <= nw.Lat && p.Lat >= se.Lat &&
|
|
p.Lon >= nw.Lon && p.Lon <= se.Lon);
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateRegions_LargerRegionSize_ProducesFewerCenters()
|
|
{
|
|
var sut = new GeofenceGridCalculator();
|
|
var nw = new GeoPoint(48.280, 37.370);
|
|
var se = new GeoPoint(48.265, 37.395);
|
|
|
|
var fineGrid = sut.GenerateRegions(nw, se, regionSizeMeters: 200);
|
|
var coarseGrid = sut.GenerateRegions(nw, se, regionSizeMeters: 1000);
|
|
|
|
coarseGrid.Count.Should().BeLessThan(fineGrid.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateRegions_VeryLargeRegionSize_AlwaysReturnsAtLeastOneCenter()
|
|
{
|
|
var sut = new GeofenceGridCalculator();
|
|
var nw = new GeoPoint(48.280, 37.370);
|
|
var se = new GeoPoint(48.265, 37.395);
|
|
|
|
var regions = sut.GenerateRegions(nw, se, regionSizeMeters: 100_000);
|
|
|
|
regions.Should().HaveCount(1);
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateRegions_NonPositiveRegionSize_Throws()
|
|
{
|
|
var sut = new GeofenceGridCalculator();
|
|
var nw = new GeoPoint(48.280, 37.370);
|
|
var se = new GeoPoint(48.265, 37.395);
|
|
|
|
Action act = () => sut.GenerateRegions(nw, se, regionSizeMeters: 0);
|
|
|
|
act.Should().Throw<ArgumentOutOfRangeException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateRegions_CountMatchesCeilingOfDiagonalSpan()
|
|
{
|
|
var sut = new GeofenceGridCalculator();
|
|
var nw = new GeoPoint(48.280, 37.370);
|
|
var se = new GeoPoint(48.265, 37.395);
|
|
|
|
var regions = sut.GenerateRegions(nw, se, regionSizeMeters: 300);
|
|
|
|
var distinctLats = regions.Select(r => r.Lat).Distinct().Count();
|
|
var distinctLons = regions.Select(r => r.Lon).Distinct().Count();
|
|
regions.Count.Should().Be(distinctLats * distinctLons);
|
|
}
|
|
}
|