fix: let OrderedCollection.GetRange take a zero-length range at the end [patch] - #60
Merged
matt-edmondson merged 1 commit intoSep 24, 2026
Conversation
…nd [patch] GetRange guarded startIndex with ThrowIfGreaterThanOrEqual(startIndex, Count), which rejects startIndex == Count. That made a zero-length range at the end of the collection impossible to request, and made GetRange unusable on an empty collection at all, even though count == 0 makes both requests valid. List<T>.GetRange explicitly allows index == Count when count == 0, and the sibling collections in this repo already agree: InsertionOrderCollection and ContiguousCollection check only startIndex >= 0, count >= 0 and startIndex + count <= Count. OrderedCollection was the only one with the extra check. Drop it and rely on the remaining three guards, which still reject every genuinely out-of-range request - including GetRange(3, 1) on a 3-element collection, via startIndex + count > Count. Adds three tests. Two fail before the change: - GetRange_ZeroCountAtEnd_ReturnsEmpty - GetRange_ZeroCountOnEmptyCollection_ReturnsEmpty and GetRange_ZeroCountMidCollection_ReturnsEmpty guards the case that already worked. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T1ntzPwg732TrH7D5vWpSV
|
matt-edmondson
deleted the
claude/containers-59-getrange-zero-length-at-end
branch
September 24, 2026 00:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #59.
OrderedCollection<T>.GetRangeguardedstartIndexwithThrowIfGreaterThanOrEqual(startIndex, Count), which rejectsstartIndex == Count. That made a zero-length range at the end of the collection impossible to request, and madeGetRangeunusable on an empty collection at all — even thoughcount == 0makes both requests perfectly valid:List<T>.GetRangeexplicitly allowsindex == Countwhencount == 0, and the sibling collections in this repo already agree —InsertionOrderCollection.GetRangeandContiguousCollection.GetRangeboth check onlystartIndex >= 0,count >= 0andstartIndex + count <= Count.OrderedCollectionwas the only one carrying the extra check, so this is as much a consistency fix as a correctness one.The change
The one line is dropped. The remaining three guards still reject every genuinely out-of-range request, which is worth spelling out because it is the reason no narrowing comes with this:
startIndexnegative →ThrowIfNegative(startIndex)countnegative →ThrowIfNegative(count)GetRange(3, 1)on a 3-element collection →startIndex + count > CountThat last one is what the existing
GetRange_InvalidStartIndex_ThrowsArgumentOutOfRangeExceptionasserts, and it still passes unmodified: the removed check was redundant for every case except the valid one it was rejecting.The XML doc gains a
<remarks>noting theList<T>parity, since the boundary is now part of the method's contract.Tests
Three added next to the existing
GetRange_ValidRange_ReturnsCorrectSubset, which only covered a mid-collection range. Verified by stashing theOrderedCollection.cschange and re-running:GetRange_ZeroCountAtEnd_ReturnsEmptystartIndex ('3') must be less than '3'GetRange_ZeroCountOnEmptyCollection_ReturnsEmptystartIndex ('0') must be less than '0'GetRange_ZeroCountMidCollection_ReturnsEmptyFull suite: 373 passed, 0 failed, 0 skipped.
🤖 Generated with Claude Code
https://claude.ai/code/session_01T1ntzPwg732TrH7D5vWpSV
Generated by Claude Code