Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test non-empty IndexSet.limitSpanningRange, documenting why max is inside #4

Merged
merged 3 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/Rearrange/IndexSet+NSRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Tests/RearrangeTests/IndexSetExtenstionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading