diff --git a/OpenNest.Core/Shapes/PipeSizes.cs b/OpenNest.Core/Shapes/PipeSizes.cs index d577a3a..b8ac4c5 100644 --- a/OpenNest.Core/Shapes/PipeSizes.cs +++ b/OpenNest.Core/Shapes/PipeSizes.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; namespace OpenNest.Shapes { @@ -7,7 +6,7 @@ namespace OpenNest.Shapes { public readonly record struct Entry(string Label, double OuterDiameter); - public static IReadOnlyList All { get; } = new List + public static IReadOnlyList All { get; } = new[] { new Entry("1/8", 0.405), new Entry("1/4", 0.540), @@ -61,9 +60,19 @@ namespace OpenNest.Shapes return false; } + /// + /// Returns all pipe sizes whose outer diameter is less than or equal to . + /// The bound is inclusive. + /// public static IEnumerable GetFittingSizes(double maxOD) { - return All.Where(e => e.OuterDiameter <= maxOD); + foreach (var entry in All) + { + if (entry.OuterDiameter <= maxOD) + { + yield return entry; + } + } } } } diff --git a/OpenNest.Tests/Shapes/PipeSizesTests.cs b/OpenNest.Tests/Shapes/PipeSizesTests.cs index bb588cd..eb12cfc 100644 --- a/OpenNest.Tests/Shapes/PipeSizesTests.cs +++ b/OpenNest.Tests/Shapes/PipeSizesTests.cs @@ -46,6 +46,16 @@ public class PipeSizesTests Assert.DoesNotContain(results, e => e.Label == "4"); } + [Fact] + public void GetFittingSizes_ExactBoundary_IsInclusive() + { + // NPS 3 has OD 3.500; passing maxOD = 3.500 should include it. + var results = PipeSizes.GetFittingSizes(3.500).ToList(); + + Assert.Contains(results, e => e.Label == "3"); + Assert.DoesNotContain(results, e => e.Label == "3 1/2"); + } + [Fact] public void GetFittingSizes_MaxSmallerThanSmallest_ReturnsEmpty() {