Have Range::overlapsWith use positive logic

Improved test to catch missing case.

llvm-svn: 188304
This commit is contained in:
Edwin Vane 2013-08-13 18:11:16 +00:00
parent c13c1b0f0d
commit c514848d1b
2 changed files with 2 additions and 3 deletions

View File

@ -48,9 +48,7 @@ public:
/// @{ /// @{
/// \brief Whether this range overlaps with \p RHS or not. /// \brief Whether this range overlaps with \p RHS or not.
bool overlapsWith(Range RHS) const { bool overlapsWith(Range RHS) const {
if ((Offset + Length) <= RHS.Offset || Offset >= (RHS.Offset + RHS.Length)) return Offset + Length > RHS.Offset && Offset < RHS.Offset + RHS.Length;
return false;
return true;
} }
/// \brief Whether this range contains \p RHS or not. /// \brief Whether this range contains \p RHS or not.

View File

@ -353,6 +353,7 @@ TEST(Range, overlaps) {
EXPECT_FALSE(Range(10, 10).overlapsWith(Range(0, 10))); EXPECT_FALSE(Range(10, 10).overlapsWith(Range(0, 10)));
EXPECT_FALSE(Range(0, 10).overlapsWith(Range(10, 10))); EXPECT_FALSE(Range(0, 10).overlapsWith(Range(10, 10)));
EXPECT_TRUE(Range(0, 10).overlapsWith(Range(2, 6))); EXPECT_TRUE(Range(0, 10).overlapsWith(Range(2, 6)));
EXPECT_TRUE(Range(2, 6).overlapsWith(Range(0, 10)));
} }
TEST(Range, contains) { TEST(Range, contains) {