diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs index 2786b1d4d4e35..945c5b03a43d2 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs @@ -132,7 +132,7 @@ internal override T MinInternal { int comp = _lBoundActive ? Comparer.Compare(_min, current.Item) : -1; - if (comp == 1) + if (comp > 0) { current = current.Right; } @@ -161,7 +161,7 @@ internal override T MaxInternal while (current != null) { int comp = _uBoundActive ? Comparer.Compare(_max, current.Item) : 1; - if (comp == -1) + if (comp < 0) { current = current.Left; } diff --git a/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs b/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs index 80daed73197cc..5e94a196c74d2 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.cs @@ -130,6 +130,23 @@ protected override ISet GenericISetFactory() { return new SortedSet(new Comparer_SameAsDefaultComparer()); } + + [Fact] + public void SortedSet_Generic_GetViewBetween_MinMax_WithCustomComparer() + { + var set = (SortedSet)CreateSortedSet(new[] { 5, 15, 25, 35, 45 }, 5, 5); + + for (int i = 0; i <= 40; i += 10) + { + for (int j = i + 10; j <= 50; j += 10) + { + SortedSet view = set.GetViewBetween(i, j); + + Assert.Equal(i + 5, view.Min); + Assert.Equal(j - 5, view.Max); + } + } + } } [OuterLoop]