mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-12 13:41:09 -05:00
test(desktop): share the square and rectangle part programs
Ten desktop test classes drew the same squares and the same 4 x 2 rectangle in private helpers, in two equivalent styles. They now use TestPrograms.Square, ClockwiseSquare and Rectangle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06ec8b1c43
commit
e5d9e12df9
11 files changed
+69
-131
No files matched your search
@@ -19,7 +19,8 @@ public class CutOffSegmentLabelTests
|
||||
view.Matrix = new Matrix();
|
||||
view.Plate.Size = new OpenNest.Geometry.Size(100, 100);
|
||||
view.Plate.Quadrant = 1;
|
||||
view.Plate.Parts.Add(new Part(new Drawing("Block", Square(20)), new Vector(40, 40)));
|
||||
view.Plate.Parts.Add(new Part(
|
||||
new Drawing("Block", TestPrograms.Square(20)), new Vector(40, 40)));
|
||||
view.Plate.CutOffs.Add(new CutOff(new Vector(50, 0), CutOffAxis.Vertical));
|
||||
view.Plate.RegenerateCutOffs(new CutOffSettings());
|
||||
|
||||
@@ -50,7 +51,8 @@ public class CutOffSegmentLabelTests
|
||||
view.Matrix = new Matrix(1, 0, 0, -1, 0, 0);
|
||||
view.Plate.Size = new OpenNest.Geometry.Size(100, 100);
|
||||
view.Plate.Quadrant = 4;
|
||||
view.Plate.Parts.Add(new Part(new Drawing("Block", Square(20)), new Vector(40, -60)));
|
||||
view.Plate.Parts.Add(new Part(
|
||||
new Drawing("Block", TestPrograms.Square(20)), new Vector(40, -60)));
|
||||
view.Plate.CutOffs.Add(new CutOff(new Vector(50, 0), CutOffAxis.Vertical));
|
||||
view.Plate.RegenerateCutOffs(new CutOffSettings());
|
||||
|
||||
@@ -95,15 +97,4 @@ public class CutOffSegmentLabelTests
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static OpenNest.CNC.Program Square(double size)
|
||||
{
|
||||
var program = new OpenNest.CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(size, 0);
|
||||
program.LineTo(size, size);
|
||||
program.LineTo(0, size);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
}
|
||||
@@ -15,22 +15,11 @@ public class CutSimulationOverlayTests
|
||||
Units = Units.Inches,
|
||||
};
|
||||
|
||||
private static Program Square(double size)
|
||||
{
|
||||
var program = new Program();
|
||||
program.Codes.Add(new RapidMove(0, 0));
|
||||
program.Codes.Add(new LinearMove(size, 0));
|
||||
program.Codes.Add(new LinearMove(size, size));
|
||||
program.Codes.Add(new LinearMove(0, size));
|
||||
program.Codes.Add(new LinearMove(0, 0));
|
||||
return program;
|
||||
}
|
||||
|
||||
private static Plate TwoSquares()
|
||||
{
|
||||
var plate = new Plate(48, 96);
|
||||
plate.Parts.Add(new Part(new Drawing("a", Square(10)), new Vector(5, 5)));
|
||||
plate.Parts.Add(new Part(new Drawing("b", Square(10)), new Vector(25, 5)));
|
||||
plate.Parts.Add(new Part(new Drawing("a", TestPrograms.Square(10)), new Vector(5, 5)));
|
||||
plate.Parts.Add(new Part(new Drawing("b", TestPrograms.Square(10)), new Vector(25, 5)));
|
||||
return plate;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ public class LayoutPartLabelZoomTests
|
||||
{
|
||||
using var view = new PlateView(ColorSchemeRegistry.Get("Workshop"));
|
||||
view.Matrix = new Matrix(scale, 0, 0, scale, 0, 0);
|
||||
var layout = LayoutPart.Create(new Part(new Drawing("Washer", Square(10)), new Vector(1, 1)), view);
|
||||
var layout = LayoutPart.Create(
|
||||
new Part(new Drawing("Washer", TestPrograms.Square(10)), new Vector(1, 1)), view);
|
||||
|
||||
using var withoutId = new Bitmap(80, 80);
|
||||
using (var g = Graphics.FromImage(withoutId))
|
||||
@@ -78,15 +79,4 @@ public class LayoutPartLabelZoomTests
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static OpenNest.CNC.Program Square(double size)
|
||||
{
|
||||
var program = new OpenNest.CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(size, 0);
|
||||
program.LineTo(size, size);
|
||||
program.LineTo(0, size);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,8 @@ public class PlateViewReorderTests
|
||||
{
|
||||
var plate = new Plate(100, 100);
|
||||
foreach (var x in new[] { 1.0, 12.0, 23.0 })
|
||||
plate.Parts.Add(new Part(new Drawing($"part {x}", Square()), new Vector(x, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing($"part {x}", TestPrograms.ClockwiseSquare(10)), new Vector(x, 1)));
|
||||
using var view = new PlateView { Plate = plate };
|
||||
var parts = plate.Parts.ToArray();
|
||||
var raised = 0;
|
||||
@@ -33,8 +34,10 @@ public class PlateViewReorderTests
|
||||
public void KeepsOneLayoutPerOccurrenceOfARepeatedPart() => StaTestThread.Run(() =>
|
||||
{
|
||||
var plate = new Plate(100, 100);
|
||||
var repeated = new Part(new Drawing("repeated", Square()), new Vector(1, 1));
|
||||
var other = new Part(new Drawing("other", Square()), new Vector(12, 1));
|
||||
var repeated = new Part(
|
||||
new Drawing("repeated", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1));
|
||||
var other = new Part(
|
||||
new Drawing("other", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1));
|
||||
plate.Parts.Add(repeated);
|
||||
plate.Parts.Add(repeated);
|
||||
plate.Parts.Add(other);
|
||||
@@ -55,7 +58,8 @@ public class PlateViewReorderTests
|
||||
{
|
||||
var plate = new Plate(100, 100);
|
||||
foreach (var x in new[] { 1.0, 12.0 })
|
||||
plate.Parts.Add(new Part(new Drawing($"part {x}", Square()), new Vector(x, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing($"part {x}", TestPrograms.ClockwiseSquare(10)), new Vector(x, 1)));
|
||||
var parts = plate.Parts.ToArray();
|
||||
var view = new PlateView { Plate = plate };
|
||||
var raised = 0;
|
||||
@@ -64,20 +68,10 @@ public class PlateViewReorderTests
|
||||
|
||||
view.Dispose();
|
||||
plate.Parts.Reorder(new[] { parts[1], parts[0] });
|
||||
plate.Parts.Add(new Part(new Drawing("late", Square()), new Vector(23, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing("late", TestPrograms.ClockwiseSquare(10)), new Vector(23, 1)));
|
||||
|
||||
Assert.Equal(0, raised);
|
||||
Assert.Equal(layouts, view.LayoutParts);
|
||||
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
|
||||
|
||||
private static CNC.Program Square()
|
||||
{
|
||||
var program = new CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(0, 10);
|
||||
program.LineTo(10, 10);
|
||||
program.LineTo(10, 0);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
}
|
||||
@@ -7,17 +7,6 @@ namespace OpenNest.WinForms.Tests.Controls;
|
||||
|
||||
public class ShapePreviewConcurrencyTests
|
||||
{
|
||||
private static Program Square(double size)
|
||||
{
|
||||
var program = new Program();
|
||||
program.Codes.Add(new RapidMove(0, 0));
|
||||
program.Codes.Add(new LinearMove(size, 0));
|
||||
program.Codes.Add(new LinearMove(size, size));
|
||||
program.Codes.Add(new LinearMove(0, size));
|
||||
program.Codes.Add(new LinearMove(0, 0));
|
||||
return program;
|
||||
}
|
||||
|
||||
// Parallel test collections paint previews on separate STA threads at once.
|
||||
// GDI+ objects are not thread-safe, so any pen, brush or font shared between
|
||||
// views fails with "Object is currently in use elsewhere".
|
||||
@@ -38,7 +27,7 @@ public class ShapePreviewConcurrencyTests
|
||||
{
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
|
||||
using var preview = new ShapePreviewControl { Size = new Size(200, 200) };
|
||||
preview.ShowDrawing(new Drawing("square", Square(10)));
|
||||
preview.ShowDrawing(new Drawing("square", TestPrograms.Square(10)));
|
||||
preview.SetInfo("10 x 10", "1 part");
|
||||
using var bitmap = new Bitmap(200, 200);
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@ public class ExpandSpacingMenuTests
|
||||
var nest = new Nest("expand job");
|
||||
var plate = nest.CreatePlate();
|
||||
plate.Size = new Size(100, 100);
|
||||
plate.Parts.Add(new Part(new Drawing("left", Square()), new Vector(1, 1)));
|
||||
plate.Parts.Add(new Part(new Drawing("right", Square()), new Vector(12, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing("left", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing("right", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1)));
|
||||
using var editor = new EditNestForm(nest) { MdiParent = host };
|
||||
editor.PlateView.SetOverlapAutoCheck(null); // Background overlap workers are irrelevant here.
|
||||
editor.Show();
|
||||
@@ -49,17 +51,6 @@ public class ExpandSpacingMenuTests
|
||||
Assert.False(host.IsExpandSpacingBusy(editor));
|
||||
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
|
||||
|
||||
private static CNC.Program Square()
|
||||
{
|
||||
var program = new CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(0, 10);
|
||||
program.LineTo(10, 10);
|
||||
program.LineTo(10, 0);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
|
||||
private static ToolStripMenuItem Menu(MainForm host, string name) =>
|
||||
(ToolStripMenuItem)host.MainMenuStrip!.Items.Find(name, true).Single();
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@ public class MainFormCharacterizationTests
|
||||
var nest = new Nest("guards");
|
||||
var plate = nest.CreatePlate();
|
||||
plate.Size = new Size(100, 100);
|
||||
plate.Parts.Add(new Part(new Drawing("left", Square()), new Vector(1, 1)));
|
||||
plate.Parts.Add(new Part(new Drawing("right", Square()), new Vector(12, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing("left", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing("right", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1)));
|
||||
using var editor = new EditNestForm(nest) { MdiParent = host };
|
||||
editor.PlateView.SetOverlapAutoCheck(null);
|
||||
editor.Show();
|
||||
@@ -96,17 +98,6 @@ public class MainFormCharacterizationTests
|
||||
.GetField($"<{property}>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic)!
|
||||
.SetValue(target, value);
|
||||
|
||||
private static CNC.Program Square()
|
||||
{
|
||||
var program = new CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(0, 10);
|
||||
program.LineTo(10, 10);
|
||||
program.LineTo(10, 0);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
|
||||
private sealed class Host : MainForm
|
||||
{
|
||||
// No startup migrations/automatic new document, and no settings save at close.
|
||||
|
||||
@@ -267,10 +267,10 @@ public class NestReportExportTests
|
||||
private static Nest CreateJob(string name)
|
||||
{
|
||||
var nest = new Nest(name) { Units = Units.Inches };
|
||||
var drawing = new Drawing("rect", Rectangle());
|
||||
var drawing = new Drawing("rect", TestPrograms.Rectangle(4, 2));
|
||||
drawing.Quantity.Required = 2;
|
||||
nest.Drawings.Add(drawing);
|
||||
nest.Drawings.Add(new Drawing("spare", Rectangle()));
|
||||
nest.Drawings.Add(new Drawing("spare", TestPrograms.Rectangle(4, 2)));
|
||||
var first = new Plate(24, 48) { Quantity = 1 };
|
||||
first.Parts.Add(new Part(drawing, new Vector(2, 2)));
|
||||
var second = new Plate(24, 48) { Quantity = 2 };
|
||||
@@ -280,17 +280,6 @@ public class NestReportExportTests
|
||||
return nest;
|
||||
}
|
||||
|
||||
private static Program Rectangle()
|
||||
{
|
||||
var program = new Program();
|
||||
program.Codes.Add(new RapidMove(0, 0));
|
||||
program.Codes.Add(new LinearMove(4, 0));
|
||||
program.Codes.Add(new LinearMove(4, 2));
|
||||
program.Codes.Add(new LinearMove(0, 2));
|
||||
program.Codes.Add(new LinearMove(0, 0));
|
||||
return program;
|
||||
}
|
||||
|
||||
private static ToolStripMenuItem Menu(MainForm host, string name) =>
|
||||
(ToolStripMenuItem)host.MainMenuStrip!.Items.Find(name, true).Single();
|
||||
|
||||
|
||||
@@ -126,24 +126,15 @@ public class OperationProgressFormTests
|
||||
private static PlateView TwoPartView()
|
||||
{
|
||||
var plate = new Plate(100, 100);
|
||||
plate.Parts.Add(new Part(new Drawing("left", Square()), new Vector(1, 1)));
|
||||
plate.Parts.Add(new Part(new Drawing("right", Square()), new Vector(12, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing("left", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1)));
|
||||
plate.Parts.Add(new Part(
|
||||
new Drawing("right", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1)));
|
||||
var view = new PlateView { Plate = plate };
|
||||
view.SelectAll();
|
||||
return view;
|
||||
}
|
||||
|
||||
private static CNC.Program Square()
|
||||
{
|
||||
var program = new CNC.Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(0, 10);
|
||||
program.LineTo(10, 10);
|
||||
program.LineTo(10, 0);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
|
||||
private static void PumpFor(TimeSpan duration)
|
||||
{
|
||||
var watch = Stopwatch.StartNew();
|
||||
|
||||
@@ -347,12 +347,12 @@ public class PlateExportTests
|
||||
private static Nest CreateJob()
|
||||
{
|
||||
var nest = new Nest("export job") { Units = Units.Inches };
|
||||
var drawing = new Drawing("rect", Rectangle());
|
||||
var drawing = new Drawing("rect", TestPrograms.Rectangle(4, 2));
|
||||
drawing.Source.Path = @"C:\drawings\rect.dxf";
|
||||
drawing.Source.Offset = new Vector(1.234567891, -0.987654321);
|
||||
drawing.Quantity.Required = 12;
|
||||
nest.Drawings.Add(drawing);
|
||||
var spare = new Drawing("spare", Rectangle());
|
||||
var spare = new Drawing("spare", TestPrograms.Rectangle(4, 2));
|
||||
spare.Source.Path = @"C:\drawings\spare.dxf";
|
||||
spare.Source.Offset = new Vector(-0.25, 0.5);
|
||||
spare.Quantity.Required = 5;
|
||||
@@ -369,17 +369,6 @@ public class PlateExportTests
|
||||
return nest;
|
||||
}
|
||||
|
||||
private static Program Rectangle()
|
||||
{
|
||||
var program = new Program();
|
||||
program.Codes.Add(new RapidMove(0, 0));
|
||||
program.Codes.Add(new LinearMove(4, 0));
|
||||
program.Codes.Add(new LinearMove(4, 2));
|
||||
program.Codes.Add(new LinearMove(0, 2));
|
||||
program.Codes.Add(new LinearMove(0, 0));
|
||||
return program;
|
||||
}
|
||||
|
||||
private static string[] ExpectedLines(Plate plate) => plate.Parts.Select(part =>
|
||||
{
|
||||
var pt = part.BaseDrawing.Source.Offset.Rotate(part.Rotation);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using OpenNest.CNC;
|
||||
|
||||
namespace OpenNest.WinForms.Tests;
|
||||
|
||||
/// <summary>Part programs the desktop tests share.</summary>
|
||||
internal static class TestPrograms
|
||||
{
|
||||
/// <summary>A width x height rectangle from the origin, counterclockwise: +X first.</summary>
|
||||
public static Program Rectangle(double width, double height)
|
||||
{
|
||||
var program = new Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(width, 0);
|
||||
program.LineTo(width, height);
|
||||
program.LineTo(0, height);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
|
||||
/// <summary>A size x size square from the origin, counterclockwise: +X first.</summary>
|
||||
public static Program Square(double size) => Rectangle(size, size);
|
||||
|
||||
/// <summary>A size x size square from the origin, clockwise: up first.</summary>
|
||||
public static Program ClockwiseSquare(double size)
|
||||
{
|
||||
var program = new Program();
|
||||
program.MoveTo(0, 0);
|
||||
program.LineTo(0, size);
|
||||
program.LineTo(size, size);
|
||||
program.LineTo(size, 0);
|
||||
program.LineTo(0, 0);
|
||||
return program;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user