feat(core): SketchGeometry (маппинги/валидация) + SketchPoint

ArcDirection, PolygonDescribe, RequirePositive, RequireVertexCount,
RequirePoints (null + finite). SketchPoint record с JSON x/y. 10 unit-тестов.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-26 21:47:05 +03:00
parent a16ee31498
commit 0bea3a0cf3
3 changed files with 100 additions and 0 deletions
@@ -0,0 +1,54 @@
using Kompas.Mcp.Core.Modeling;
namespace Kompas.Mcp.Tests;
[Trait("Category", "Unit")]
public sealed class SketchGeometryTests
{
[Theory]
[InlineData(true, 1)]
[InlineData(false, -1)]
public void ArcDirection_maps_orientation(bool ccw, int expected)
=> Assert.Equal(expected, (int)SketchGeometry.ArcDirection(ccw));
[Theory]
[InlineData(true, false)] // вписанный → describe=false
[InlineData(false, true)] // описанный → describe=true
public void PolygonDescribe_inverts_inscribed(bool inscribed, bool expected)
=> Assert.Equal(expected, SketchGeometry.PolygonDescribe(inscribed));
[Fact]
public void RequirePositive_throws_on_zero_or_negative()
{
Assert.Throws<ArgumentOutOfRangeException>(() => SketchGeometry.RequirePositive(0, "radius"));
Assert.Throws<ArgumentOutOfRangeException>(() => SketchGeometry.RequirePositive(-1, "radius"));
Assert.Null(Record.Exception(() => SketchGeometry.RequirePositive(0.1, "radius")));
}
[Fact]
public void RequireVertexCount_throws_below_three()
{
Assert.Throws<ArgumentOutOfRangeException>(() => SketchGeometry.RequireVertexCount(2));
Assert.Null(Record.Exception(() => SketchGeometry.RequireVertexCount(3)));
}
[Fact]
public void RequirePoints_throws_on_null()
=> Assert.Throws<ArgumentNullException>(
() => SketchGeometry.RequirePoints(null!, 2, "points"));
[Fact]
public void RequirePoints_throws_when_too_few()
=> Assert.Throws<ArgumentException>(
() => SketchGeometry.RequirePoints(new[] { (0.0, 0.0) }, 2, "points"));
[Fact]
public void RequirePoints_throws_on_non_finite()
=> Assert.Throws<ArgumentException>(
() => SketchGeometry.RequirePoints(new[] { (0.0, 0.0), (double.NaN, 1.0) }, 2, "points"));
[Fact]
public void RequirePoints_passes_on_valid()
=> Assert.Null(Record.Exception(
() => SketchGeometry.RequirePoints(new[] { (0.0, 0.0), (1.0, 1.0) }, 2, "points")));
}