Skip to content

Commit 35d403e

Browse files
committed
More tests.
1 parent 8ccf371 commit 35d403e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

interval_tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace lib_interval_tree
146146
{
147147
if (overlaps(other))
148148
return 0;
149-
if (high_ < other.low)
149+
if (high_ < other.low_)
150150
return other.low_ - high_;
151151
else
152152
return low_ - other.high_;

tests/interval_tests.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ class OverlapTests
2121
class ContainmentTests
2222
: public ::testing::Test
2323
{
24+
public:
25+
using types = IntervalTypes <int>;
26+
};
27+
28+
class DistanceTests
29+
: public ::testing::Test
30+
{
2431
public:
2532
using types = IntervalTypes <int>;
2633
};
@@ -188,6 +195,7 @@ TEST_F(ContainmentTests, ExpectIntervalWithinOther)
188195
EXPECT_EQ(base.within({-73, -23}), true);
189196
EXPECT_EQ(base.within({-100, -100}), true);
190197
EXPECT_EQ(base.within({100, 100}), true);
198+
EXPECT_EQ(base.within({0, 0}), true);
191199
}
192200

193201
TEST_F(ContainmentTests, ExpectIntervalNotWithinOther)
@@ -200,3 +208,11 @@ TEST_F(ContainmentTests, ExpectIntervalNotWithinOther)
200208
EXPECT_EQ(base.within({-200, -101}), false);
201209
EXPECT_EQ(base.within({200, 300}), false);
202210
}
211+
212+
TEST_F(DistanceTests, DistanceIsZeroOnOverlap)
213+
{
214+
auto base = types::interval_type{-35, 96};
215+
216+
auto other = types::interval_type{-20, 600};
217+
EXPECT_EQ(base - other, 0);
218+
}

0 commit comments

Comments
 (0)