using OpenNest.Geometry; namespace OpenNest.Desktop.Tests.Plates; public class PlateEditValuesTests { private static SheetOutline Ell() => new(new[] { new Vector(0, 0), new Vector(96, 0), new Vector(96, 24), new Vector(48, 24), new Vector(48, 48), new Vector(0, 48), }); [Fact] public void FromPlate_ReadsEveryValue_AndApplyToWritesThemBack() { var plate = new Plate(new Size(48, 96)) { Quantity = 4, PartSpacing = 0.25, Quadrant = 3 }; plate.EdgeSpacing.Left = 1; plate.EdgeSpacing.Top = 2; plate.EdgeSpacing.Right = 3; plate.EdgeSpacing.Bottom = 4; var values = PlateEditValues.FromPlate(plate); Assert.Equal(new Size(48, 96), values.Size); Assert.Equal(4, values.Quantity); Assert.Equal(0.25, values.PartSpacing); Assert.Equal(3, values.Quadrant); Assert.Equal((1, 2, 3, 4), (values.LeftSpacing, values.TopSpacing, values.RightSpacing, values.BottomSpacing)); Assert.Null(values.Outline); var other = new Plate(new Size(10, 10)); values.ApplyTo(other); Assert.Equal(PlateEditValues.FromPlate(plate), PlateEditValues.FromPlate(other)); } [Theory] [InlineData(1, 1, 1, 1, true)] [InlineData(48, 48, 1, 1, false)] // left + right reach the length [InlineData(1, 1, 24, 24, false)] // top + bottom reach the width public void CanApply_NeedsRoomOnTheSheetBothWays(double left, double right, double top, double bottom, bool expected) { var values = new PlateEditValues { Size = new Size(48, 96), LeftSpacing = left, RightSpacing = right, TopSpacing = top, BottomSpacing = bottom, }; Assert.Equal(expected, values.CanApply); } [Fact] public void CanApplyWithSize_NeedsASizeThatParses() { var values = new PlateEditValues(); Assert.True(values.CanApplyWithSize("48 x 96", out var size)); Assert.Equal(new Size(48, 96), size); Assert.False(values.CanApplyWithSize("48 by", out _)); Assert.False(values.CanApplyWithSize("0 x 0", out _)); } [Fact] public void AnOutline_SetsTheSize_AndApplyKeepsIt() { var plate = new Plate(new Size(60, 120)); var values = PlateEditValues.FromPlate(plate).WithOutline(Ell()); Assert.Equal(new Size(48, 96), values.Size); values.ApplyTo(plate); Assert.Equal(Ell(), plate.Outline); Assert.Equal(new Size(48, 96), plate.Size); } [Fact] public void ClearingTheOutline_LeavesARectangleOfTheSameSize() { var plate = new Plate { Outline = Ell(), Quadrant = 2 }; var values = PlateEditValues.FromPlate(plate).WithOutline(null); values.ApplyTo(plate); Assert.Null(plate.Outline); Assert.Equal(new Size(48, 96), plate.Size); Assert.Equal(2, plate.Quadrant); } [Fact] public void OutlineText_DescribesTheSheet() { Assert.Equal("Rectangular sheet", PlateEditValues.OutlineText(null)); Assert.Equal("6 vertices", PlateEditValues.OutlineText(Ell())); } [Theory] [InlineData(Units.Inches, 0.25)] [InlineData(Units.Millimeters, 1)] public void SpacingIncrement_IsAQuarterInchOrAMillimeter(Units units, double expected) => Assert.Equal(expected, PlateEditValues.SpacingIncrement(units)); }