mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-07 20:05:46 -05:00
Nest reports showed "-" for every part weight on N26-295 because the nest and its drawings store Stainless Steel 310 with density 0: materials are picked by name and grade, and nothing copies a density onto them. The densities live in the machine material defaults, and for this nest not even on its own machine (CL-980 lists only 304; 310 is on CI FIBER 4020). The desktop now resolves a catalog density before capturing the report: the nest machine's exact name and grade, any machine's exact name and grade, then the same material name. A density stored on the nest still wins, and the drawing's own material stays the last fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using OpenNest.Data;
|
|
|
|
namespace OpenNest.Tests.Data;
|
|
|
|
public class MaterialDensityLookupTests
|
|
{
|
|
private static MaterialConfig M(string name, string grade, double density) =>
|
|
new() { Name = name, Grade = grade, Density = density };
|
|
|
|
private static MachineConfig Machine(params MaterialConfig[] materials) =>
|
|
new() { Name = "CL-980", Materials = materials.ToList() };
|
|
|
|
[Fact]
|
|
public void Resolve_PrefersTheNestMachineExactGrade()
|
|
{
|
|
var machine = Machine(M("Stainless Steel", "310", 0.287));
|
|
var catalog = new[] { M("Stainless Steel", "310", 0.3) };
|
|
|
|
Assert.Equal(0.287, MaterialDensityLookup.Resolve("Stainless Steel", "310", machine, catalog));
|
|
}
|
|
|
|
[Fact]
|
|
public void Resolve_ExactGradeOnAnotherMachineBeatsTheSameNameOnTheNestMachine()
|
|
{
|
|
// N26-295: CL-980 lists only 304; the 310 grade lives on another machine.
|
|
var machine = Machine(M("Stainless Steel", "304", 0.289));
|
|
var catalog = new[] { M("Stainless Steel", "304", 0.289), M("stainless steel", " 310 ", 0.287) };
|
|
|
|
Assert.Equal(0.287, MaterialDensityLookup.Resolve("Stainless Steel", "310", machine, catalog));
|
|
}
|
|
|
|
[Fact]
|
|
public void Resolve_FallsBackToTheMaterialNameWhenNoGradeMatches()
|
|
{
|
|
var machine = Machine(M("Stainless Steel", "304", 0.289));
|
|
|
|
Assert.Equal(0.289, MaterialDensityLookup.Resolve("Stainless Steel", "17-4", machine, null));
|
|
}
|
|
|
|
[Fact]
|
|
public void Resolve_SkipsEntriesWithoutADensity()
|
|
{
|
|
var machine = Machine(M("Stainless Steel", "310", 0));
|
|
var catalog = new[] { M("Stainless Steel", "310", 0.287) };
|
|
|
|
Assert.Equal(0.287, MaterialDensityLookup.Resolve("Stainless Steel", "310", machine, catalog));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData("Brass")]
|
|
public void Resolve_IsZeroWhenNothingMatches(string? name)
|
|
{
|
|
var machine = Machine(M("Stainless Steel", "310", 0.287));
|
|
|
|
Assert.Equal(0, MaterialDensityLookup.Resolve(name, "310", machine, null));
|
|
}
|
|
}
|