style: apply CSharpier formatting to all C# sources
Repo-wide sweep with the pinned CSharpier 1.3.0 tool. Whitespace and line-wrapping only; OpenNest.Engine.Tests (109) and OpenNest.IO.Tests pass after reformat, full solution builds 0 errors. Added .csharpierignore so csproj/config XML keeps its existing layout (CSharpier's XML wrapping churns attributes with zero benefit). Formatting is now enforceable: dotnet csharpier check . passes.
This commit is contained in:
@@ -10,33 +10,54 @@ public class JobAdapterTests
|
||||
{
|
||||
var drawing = new Drawing("same name", TestDrawingFactory.Rectangle());
|
||||
drawing.Quantity.Required = 9;
|
||||
var item = new NestItem { Drawing = drawing, Quantity = 3, Priority = 7, StepAngle = 0 };
|
||||
var sourcePlate = new Plate(100, 200) { Quantity = 3, PartSpacing = 2 };
|
||||
var job = new NestJob(new[] { DrawingJobMapper.FromItem("requirement", item) },
|
||||
new[] { DrawingJobMapper.FromPlate("stock", sourcePlate, 3) });
|
||||
var quantities = new List<int>();
|
||||
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(p, items =>
|
||||
var item = new NestItem
|
||||
{
|
||||
var privateItem = Assert.Single(items);
|
||||
quantities.Add(privateItem.Quantity);
|
||||
Assert.NotSame(drawing, privateItem.Drawing);
|
||||
Assert.Equal(0, privateItem.StepAngle);
|
||||
Assert.Equal(7, privateItem.Priority);
|
||||
var part = new Part(privateItem.Drawing);
|
||||
privateItem.Quantity = 0;
|
||||
privateItem.Drawing.Quantity.Required = 0;
|
||||
return new List<Part> { part };
|
||||
}));
|
||||
Drawing = drawing,
|
||||
Quantity = 3,
|
||||
Priority = 7,
|
||||
StepAngle = 0,
|
||||
};
|
||||
var sourcePlate = new Plate(100, 200) { Quantity = 3, PartSpacing = 2 };
|
||||
var job = new NestJob(
|
||||
new[] { DrawingJobMapper.FromItem("requirement", item) },
|
||||
new[] { DrawingJobMapper.FromPlate("stock", sourcePlate, 3) }
|
||||
);
|
||||
var quantities = new List<int>();
|
||||
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(
|
||||
p,
|
||||
items =>
|
||||
{
|
||||
var privateItem = Assert.Single(items);
|
||||
quantities.Add(privateItem.Quantity);
|
||||
Assert.NotSame(drawing, privateItem.Drawing);
|
||||
Assert.Equal(0, privateItem.StepAngle);
|
||||
Assert.Equal(7, privateItem.Priority);
|
||||
var part = new Part(privateItem.Drawing);
|
||||
privateItem.Quantity = 0;
|
||||
privateItem.Drawing.Quantity.Required = 0;
|
||||
return new List<Part> { part };
|
||||
}
|
||||
));
|
||||
var result = new NestJobRunner(_ => adapter).Solve(job);
|
||||
var materialized = NestResultMaterializer.Materialize(job, result);
|
||||
Assert.Equal(new[] { 3, 2, 1 }, quantities);
|
||||
Assert.Equal(NestJobStatus.Complete, result.Status);
|
||||
Assert.Equal(3, materialized.Nest.Plates.Count);
|
||||
Assert.All(materialized.Nest.Plates, p => { Assert.Equal(1, p.Quantity); Assert.Single(p.Parts); });
|
||||
Assert.All(
|
||||
materialized.Nest.Plates,
|
||||
p =>
|
||||
{
|
||||
Assert.Equal(1, p.Quantity);
|
||||
Assert.Single(p.Parts);
|
||||
}
|
||||
);
|
||||
var outputDrawing = materialized.DrawingsByPartId["requirement"];
|
||||
Assert.Equal(3, outputDrawing.Quantity.Required);
|
||||
Assert.Equal(3, outputDrawing.Quantity.Nested);
|
||||
Assert.All(materialized.Nest.Plates, p => Assert.Same(outputDrawing, p.Parts[0].BaseDrawing));
|
||||
Assert.All(
|
||||
materialized.Nest.Plates,
|
||||
p => Assert.Same(outputDrawing, p.Parts[0].BaseDrawing)
|
||||
);
|
||||
Assert.NotSame(drawing, outputDrawing);
|
||||
Assert.Equal(9, drawing.Quantity.Required);
|
||||
Assert.Equal(0, drawing.Quantity.Nested);
|
||||
@@ -44,26 +65,38 @@ public class JobAdapterTests
|
||||
Assert.Equal(3, sourcePlate.Quantity);
|
||||
Assert.Empty(sourcePlate.Parts);
|
||||
Assert.Equal(2, sourcePlate.PartSpacing);
|
||||
Assert.Equal(PartGeometrySnapshot.FromProgram(TestDrawingFactory.Rectangle()).Motions,
|
||||
PartGeometrySnapshot.FromProgram(drawing.Program).Motions);
|
||||
Assert.Equal(
|
||||
PartGeometrySnapshot.FromProgram(TestDrawingFactory.Rectangle()).Motions,
|
||||
PartGeometrySnapshot.FromProgram(drawing.Program).Motions
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReferenceIdentityNotNamesControlsLegacyPlacements()
|
||||
{
|
||||
var drawing = new Drawing("duplicate", TestDrawingFactory.Rectangle());
|
||||
var job = new NestJob(new[] { DrawingJobMapper.FromDrawing("a", drawing, 1),
|
||||
DrawingJobMapper.FromDrawing("b", drawing, 1) }, FiniteStockJobTests.Job(1).Plates);
|
||||
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(p, items =>
|
||||
{
|
||||
Assert.NotSame(items[0].Drawing, items[1].Drawing);
|
||||
foreach (var item in items) item.Drawing.Name = "identical";
|
||||
return new List<Part>
|
||||
var job = new NestJob(
|
||||
new[]
|
||||
{
|
||||
new Part(items[0].Drawing, new Vector(0, 0)),
|
||||
new Part(items[1].Drawing, new Vector(10, 0))
|
||||
};
|
||||
}));
|
||||
DrawingJobMapper.FromDrawing("a", drawing, 1),
|
||||
DrawingJobMapper.FromDrawing("b", drawing, 1),
|
||||
},
|
||||
FiniteStockJobTests.Job(1).Plates
|
||||
);
|
||||
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(
|
||||
p,
|
||||
items =>
|
||||
{
|
||||
Assert.NotSame(items[0].Drawing, items[1].Drawing);
|
||||
foreach (var item in items)
|
||||
item.Drawing.Name = "identical";
|
||||
return new List<Part>
|
||||
{
|
||||
new Part(items[0].Drawing, new Vector(0, 0)),
|
||||
new Part(items[1].Drawing, new Vector(10, 0)),
|
||||
};
|
||||
}
|
||||
));
|
||||
var result = new NestJobRunner(_ => adapter).Solve(job);
|
||||
Assert.Equal(new[] { "a", "b" }, result.Plates[0].Placements.Select(p => p.PartId));
|
||||
var output = NestResultMaterializer.Materialize(job, result);
|
||||
@@ -74,10 +107,19 @@ public class JobAdapterTests
|
||||
[Fact]
|
||||
public void UnknownPrivateDrawingIsRejectedEvenWithMatchingName()
|
||||
{
|
||||
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(p, items => new List<Part>
|
||||
{ new(new Drawing(items[0].Drawing.Name, TestDrawingFactory.Rectangle())) }));
|
||||
Assert.Throws<InvalidOperationException>(() => new NestJobRunner(_ => adapter).Solve(FiniteStockJobTests.Job()));
|
||||
Assert.Throws<NotSupportedException>(() => LegacyPlateNesterAdapter.Create("not registered"));
|
||||
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(
|
||||
p,
|
||||
items => new List<Part>
|
||||
{
|
||||
new(new Drawing(items[0].Drawing.Name, TestDrawingFactory.Rectangle())),
|
||||
}
|
||||
));
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
new NestJobRunner(_ => adapter).Solve(FiniteStockJobTests.Job())
|
||||
);
|
||||
Assert.Throws<NotSupportedException>(() =>
|
||||
LegacyPlateNesterAdapter.Create("not registered")
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -103,17 +145,26 @@ public class JobAdapterTests
|
||||
incremental.LineTo(7, 4);
|
||||
var incrementalSnapshot = PartGeometrySnapshot.FromProgram(incremental);
|
||||
Assert.Equal(Mode.Incremental, DrawingJobMapper.ToProgram(incrementalSnapshot).Mode);
|
||||
Assert.Equal(incrementalSnapshot.Motions,
|
||||
PartGeometrySnapshot.FromProgram(DrawingJobMapper.ToProgram(incrementalSnapshot)).Motions);
|
||||
Assert.Equal(
|
||||
incrementalSnapshot.Motions,
|
||||
PartGeometrySnapshot
|
||||
.FromProgram(DrawingJobMapper.ToProgram(incrementalSnapshot))
|
||||
.Motions
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RealDefaultEngineRunsFromDrawingThroughMaterialization()
|
||||
{
|
||||
var drawing = new Drawing("generated asymmetric rectangle", TestDrawingFactory.Rectangle(13, 7));
|
||||
var drawing = new Drawing(
|
||||
"generated asymmetric rectangle",
|
||||
TestDrawingFactory.Rectangle(13, 7)
|
||||
);
|
||||
drawing.Quantity.Required = 1;
|
||||
var job = new NestJob(new[] { DrawingJobMapper.FromDrawing("rectangle", drawing, 1) },
|
||||
new[] { new NestPlateStock("sheet", new Size(40, 60), 1, 1, new Spacing(2, 2, 2, 2)) });
|
||||
var job = new NestJob(
|
||||
new[] { DrawingJobMapper.FromDrawing("rectangle", drawing, 1) },
|
||||
new[] { new NestPlateStock("sheet", new Size(40, 60), 1, 1, new Spacing(2, 2, 2, 2)) }
|
||||
);
|
||||
var result = new NestJobRunner(LegacyPlateNesterAdapter.Create).Solve(job);
|
||||
Assert.Equal(NestJobStatus.Complete, result.Status);
|
||||
Assert.Equal(new StockUsage("sheet", 1, 0), Assert.Single(result.StockUsage));
|
||||
@@ -140,10 +191,13 @@ public class JobAdapterTests
|
||||
{
|
||||
var program = TestDrawingFactory.Rectangle();
|
||||
program.Offset(-5, 3);
|
||||
var job = new NestJob(new[] { new NestJobPart("p", PartGeometrySnapshot.FromProgram(program), 1) },
|
||||
FiniteStockJobTests.Job(1).Plates);
|
||||
var result = new NestJobRunner(_ => new FiniteStockJobTests.Nester(_ => new PlateCandidate(new[]
|
||||
{ new NestJobPlacement("p", 0, 23, 31, 0.7) }))).Solve(job);
|
||||
var job = new NestJob(
|
||||
new[] { new NestJobPart("p", PartGeometrySnapshot.FromProgram(program), 1) },
|
||||
FiniteStockJobTests.Job(1).Plates
|
||||
);
|
||||
var result = new NestJobRunner(_ => new FiniteStockJobTests.Nester(_ => new PlateCandidate(
|
||||
new[] { new NestJobPlacement("p", 0, 23, 31, 0.7) }
|
||||
))).Solve(job);
|
||||
var output = NestResultMaterializer.Materialize(job, result);
|
||||
var part = output.Nest.Plates[0].Parts[0];
|
||||
var expected = new Vector(-5, 3).Rotate(0.7);
|
||||
@@ -152,11 +206,16 @@ public class JobAdapterTests
|
||||
Assert.Equal(new Vector(23, 31), part.Location);
|
||||
}
|
||||
|
||||
private sealed class MutatingEngine(Plate plate, Func<List<NestItem>, List<Part>> nest) : NestEngineBase(plate)
|
||||
private sealed class MutatingEngine(Plate plate, Func<List<NestItem>, List<Part>> nest)
|
||||
: NestEngineBase(plate)
|
||||
{
|
||||
public override string Name => "test";
|
||||
public override string Description => "mutates private demand";
|
||||
public override List<Part> Nest(List<NestItem> items, IProgress<NestProgress> progress, CancellationToken token)
|
||||
=> nest(items);
|
||||
|
||||
public override List<Part> Nest(
|
||||
List<NestItem> items,
|
||||
IProgress<NestProgress> progress,
|
||||
CancellationToken token
|
||||
) => nest(items);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user