diff --git a/Sources/Rearrange/IndexSet+NSRange.swift b/Sources/Rearrange/IndexSet+NSRange.swift index 399e908..5e2c35a 100644 --- a/Sources/Rearrange/IndexSet+NSRange.swift +++ b/Sources/Rearrange/IndexSet+NSRange.swift @@ -51,9 +51,11 @@ public extension IndexSet { return intersects(integersIn: elementRange) } - /// Returns a range starting at the minimum of the test and extending to the maximum + /// Returns a range encompassing the minimum and maximum value of the set. /// - /// This value will be nil if either min() or max() are nil + /// The resulting range includes both minimum and maximum boundaries of `self` because these describe indices that should be part of the range, not past-end positions. + /// + /// This value will be nil if either `min()` or `max()` are `nil`. var limitSpanningRange: NSRange? { guard let start = self.min(), let end = self.max() else { return nil diff --git a/Tests/RearrangeTests/IndexSetExtenstionTests.swift b/Tests/RearrangeTests/IndexSetExtenstionTests.swift index 5d59ebc..c100c16 100644 --- a/Tests/RearrangeTests/IndexSetExtenstionTests.swift +++ b/Tests/RearrangeTests/IndexSetExtenstionTests.swift @@ -17,6 +17,18 @@ class IndexSetExtenstionTests: XCTestCase { XCTAssertEqual(set.limitSpanningRange, NSRange(location: 0, length: 5)) } + func testLimitSpanningRangeWithOneIndex() { + let set = IndexSet([42]) + + XCTAssertEqual(set.limitSpanningRange, NSRange(location: 42, length: 1)) + } + + func testLimitSpanningRangeWithMultipleIndices() { + let set = IndexSet([1, 7, 3]) + + XCTAssertEqual(set.limitSpanningRange, NSRange(1...7)) + } + func testLimitSpanningRangeWithEmptySet() { let set = IndexSet()