Skip to content

Commit

Permalink
Merge pull request swiftlang#1325 from odnoletkov/stdlib-interval-ove…
Browse files Browse the repository at this point in the history
…rlaps

[stdlib] Fixed IntervalType.overlaps for empty interval case
  • Loading branch information
gribozavr committed Feb 16, 2016
2 parents d7d87a1 + 9fffeda commit 532d36d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stdlib/public/core/Interval.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ extension ClosedInterval {
}

extension IntervalType {
/// Returns `true` if `lhs` and `rhs` have a non-empty intersection.
/// Returns `true` iff `lhs` and `rhs` have a non-empty intersection.
@warn_unused_result
public func overlaps<
I: IntervalType where I.Bound == Bound
>(other: I) -> Bool {
return contains(other.start) || other.contains(start)
return (!other.isEmpty && contains(other.start))
|| (!isEmpty && other.contains(start))
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/1_stdlib/Interval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ IntervalTestSuite.test("Overlaps") {
expectOverlaps(true, 0..<20, 5...10)
expectOverlaps(true, 0...20, 5..<10)
expectOverlaps(true, 0...20, 5...10)

// 0-0, 0-5
expectOverlaps(false, 0..<0, 0..<5)
expectOverlaps(false, 0..<0, 0...5)

}

IntervalTestSuite.test("Emptiness") {
Expand Down

0 comments on commit 532d36d

Please sign in to comment.