Files
OpenNest/OpenNest.Engine.Tests/Jobs/NestJobEngineSelectionTests.cs
T
aj 0a1d021bf7 refactor(engine): rename the Default engine and fill strategy to Fill
The multi-phase lattice fill (linear, pairs, rectangle best-fit, remainder) is
no longer meant to be the engine used by default, so it gets a name for what
it does. The registry lists it as Fill and maps the old name Default to it;
PlateFillService, PlateNesterFactory and NestJobOptions use Fill, and every
fill-strategy caller still accepts Default. Console --autonest now validates
engine names through NestingEngineRegistry.ResolveName so renamed names work.

Layouts are unchanged: Default and Fill resolve to the same fillers and the
golden layouts pass under the new name.
2026-10-06 12:11:03 -04:00

71 lines
2.6 KiB
C#

using OpenNest.Engine.Jobs;
using OpenNest.Engine.Jobs.Adapters;
using OpenNest.Geometry;
namespace OpenNest.Engine.Tests.Jobs;
/// <summary>
/// Strategy selection is instance-scoped: explicit engine choices complete independently,
/// and unknown strategies are rejected.
/// </summary>
public class NestJobEngineSelectionTests
{
[Fact]
public void ExplicitDefaultAndStripSelectionsCompleteIndependently()
{
var job = FiniteStockJobTests.Job(1);
var defaultResult = new NestJobRunner(PlateNesterFactory.Create).Solve(job);
Assert.Equal(NestJobStatus.Complete, defaultResult.Status);
var stripResult = new NestJobRunner(PlateNesterFactory.Create).Solve(
new NestJob(job.Parts, job.Plates, new NestJobOptions("Strip"))
);
Assert.Equal(NestJobStatus.Complete, stripResult.Status);
}
[Fact]
public void FactoryResolvesEachNamedBuiltInStrategy()
{
var defaultNester = PlateNesterFactory.Create("Fill");
var stripNester = PlateNesterFactory.Create("Strip");
var verticalNester = PlateNesterFactory.Create("Vertical Remnant");
var horizontalNester = PlateNesterFactory.Create("Horizontal Remnant");
Assert.NotNull(defaultNester);
Assert.NotNull(stripNester);
Assert.NotNull(verticalNester);
Assert.NotNull(horizontalNester);
Assert.NotSame(defaultNester, stripNester);
}
[Fact]
public void UnknownStrategyIsRejected()
{
Assert.Throws<NotSupportedException>(() => PlateNesterFactory.Create("Not A Real Engine"));
var job = FiniteStockJobTests.Job(1);
Assert.Throws<NotSupportedException>(() =>
new NestJobRunner(key =>
throw new NotSupportedException($"Unknown placement strategy: {key}")
).Solve(new NestJob(job.Parts, job.Plates, new NestJobOptions("Bogus")))
);
}
[Fact]
public void StripEngineEndToEndPlacesAndAccounts()
{
var drawing = new Drawing("strip part", TestDrawingFactory.Rectangle(30, 30));
var job = new NestJob(
new[] { DrawingJobMapper.FromDrawing("part", drawing, 2) },
new[] { new NestPlateStock("s", new Size(90, 90), 1) }
);
var result = new NestJobRunner(PlateNesterFactory.Create).Solve(
new NestJob(job.Parts, job.Plates, new NestJobOptions("Strip"))
);
Assert.True(result.Plates.SelectMany(p => p.Placements).Count() >= 1);
foreach (var f in result.Fulfillment)
Assert.Equal(f.Requested, f.Placed + f.Unplaced);
}
}