Files
OpenNest/OpenNest.Tests/Data/ThicknessNamesTests.cs
T
ajandClaude Opus 5.5 6b161d7a8b feat(data): store a nest's thickness name and show it
Nests showed only the decimal (0.135), while the shop thinks in gauges.
A nest now keeps a ThicknessName in its file, record and the server
(schema v20), set from Nest Information's new box, which suggests the
machine's name or the nearest standard gauge. The Open list, status bar
and reports show "10 ga (0.135)"; nests saved without a name get one
looked up for display only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:02:41 -05:00

116 lines
3.8 KiB
C#

using OpenNest.Data;
namespace OpenNest.Tests.Data;
public class ThicknessNamesTests
{
private static MachineConfig Machine(UnitSystem units = UnitSystem.Inches, double value = 0.135, string name = "10 ga") => new()
{
Name = "Fiber 1",
Units = units,
Materials =
{
new MaterialConfig
{
Name = "Mild Steel",
Grade = "HR",
Thicknesses = { new ThicknessConfig { Value = value, Name = name } },
},
},
};
[Fact]
public void Format_PutsTheDecimalInParentheses()
{
Assert.Equal("10 ga (0.135)", ThicknessNames.Format(" 10 ga ", 0.135));
Assert.Equal("0.135", ThicknessNames.Format("", 0.135));
Assert.Equal("0.135", ThicknessNames.Format(null, 0.135));
}
[Fact]
public void For_TakesTheMachinesNameForTheMaterialAndThickness()
{
var machines = new[] { Machine(name: "10 gauge") };
Assert.Equal("10 gauge", ThicknessNames.For(machines, "mild steel", "hr", 0.135, Units.Inches));
// Another material falls back to the standard gauges.
Assert.Equal("10 ga", ThicknessNames.For(machines, "Aluminum", "", 0.135, Units.Inches));
}
[Fact]
public void For_ConvertsBetweenTheNestAndMachineUnits()
{
var machines = new[] { Machine(UnitSystem.Millimeters, 3.429, "10 gauge") };
Assert.Equal("10 gauge", ThicknessNames.For(machines, "Mild Steel", "HR", 0.135, Units.Inches));
}
[Fact]
public void For_SkipsAMachineThatLeavesTheThicknessUnnamed()
{
var machines = new[] { Machine(name: ""), Machine(name: "Ten") };
Assert.Equal("Ten", ThicknessNames.For(machines, "Mild Steel", "HR", 0.135, Units.Inches));
}
[Theory]
[InlineData(0.135, "10 ga")]
[InlineData(0.06, "16 ga")]
[InlineData(0.075, "14 ga")]
[InlineData(0.105, "12 ga")]
[InlineData(0.188, "3/16\"")]
[InlineData(0.25, "1/4\"")]
[InlineData(0.3, "")]
[InlineData(0, "")]
public void For_NamesTheShopsRoundedDecimalsByTheNearestStandardEntry(double thickness, string expected)
{
Assert.Equal(expected, ThicknessNames.For(Array.Empty<MachineConfig>(), "Mild Steel", "HR", thickness, Units.Inches));
}
[Fact]
public void For_ReadsMillimeterNests()
{
Assert.Equal("10 ga", ThicknessNames.For(Array.Empty<MachineConfig>(), "", "", 3.43, Units.Millimeters));
}
[Fact]
public void FormatRecord_PrefersTheStoredName()
{
var record = new NestRecord { Material = "Mild Steel", MaterialGrade = "HR", Thickness = 0.135, ThicknessName = "Ten" };
var machines = new[] { Machine() };
Assert.Equal("Ten (0.135)", ThicknessNames.Format(record, machines));
record.ThicknessName = "";
Assert.Equal("10 ga (0.135)", ThicknessNames.Format(record, machines));
record.Thickness = 0;
Assert.Equal("0", ThicknessNames.Format(record, machines));
}
[Fact]
public void NewThickness_ClearsTheNameOfTheOldOne()
{
var nest = new Nest { Thickness = 0.135, ThicknessName = " 10 ga " };
Assert.Equal("10 ga", nest.ThicknessName);
nest.Thickness = 0.135;
Assert.Equal("10 ga", nest.ThicknessName);
nest.Thickness = 0.25;
Assert.Equal("", nest.ThicknessName);
}
[Fact]
public void NestRecord_CarriesTheNameBothWays()
{
var nest = new Nest { Name = "N1", Thickness = 0.135, ThicknessName = "10 ga" };
var record = NestRecordFactory.FromNest(nest, Guid.Empty, 0);
Assert.Equal("10 ga", record.ThicknessName);
var loaded = new Nest();
NestRecordFactory.ApplyMetadata(loaded, record);
Assert.Equal(0.135, loaded.Thickness);
Assert.Equal("10 ga", loaded.ThicknessName);
}
}