Skip to content

Commit f61c645

Browse files
committed
More tests.
1 parent 35d403e commit f61c645

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

interval_tree.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ namespace lib_interval_tree
169169
return {std::min(low_, other.low_), std::max(high_, other.high_)};
170170
}
171171

172-
#ifdef PUBLICIZE
172+
#ifdef LIB_INTERVAL_TREE_PUBLICIZE
173173
public:
174174
#else
175175
private:
176-
#endif // PUBLICIZE
176+
#endif // LIB_INTERVAL_TREE_PUBLICIZE
177177
value_type low_;
178178
value_type high_;
179179
};
@@ -254,11 +254,11 @@ namespace lib_interval_tree
254254
}
255255
}
256256

257-
#ifdef PUBLICIZE
257+
#ifdef LIB_INTERVAL_TREE_PUBLICIZE
258258
public:
259259
#else
260260
private:
261-
#endif // PUBLICIZE
261+
#endif // LIB_INTERVAL_TREE_PUBLICIZE
262262
interval_type interval_;
263263
value_type max_;
264264
node* parent_;
@@ -305,11 +305,11 @@ namespace lib_interval_tree
305305
{
306306
}
307307

308-
#ifdef PUBLICIZE
308+
#ifdef LIB_INTERVAL_TREE_PUBLICIZE
309309
public:
310310
#else
311311
protected:
312-
#endif // PUBLICIZE
312+
#endif // LIB_INTERVAL_TREE_PUBLICIZE
313313
node_ptr_t node_;
314314
owner_type owner_;
315315
};
@@ -1205,11 +1205,11 @@ namespace lib_interval_tree
12051205
x->color_ = rb_color::black;
12061206
}
12071207

1208-
#ifdef PUBLICIZE
1208+
#ifdef LIB_INTERVAL_TREE_PUBLICIZE
12091209
public:
12101210
#else
12111211
private:
1212-
#endif // PUBLICIZE
1212+
#endif // LIB_INTERVAL_TREE_PUBLICIZE
12131213
node_type* root_;
12141214
size_type size_;
12151215
};

tests/insert_tests.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ TEST_F(InsertTests, InsertIntoEmpty2)
2828

2929
TEST_F(InsertTests, InsertMultipleIntoEmpty)
3030
{
31-
tree.insert({0, 16});
32-
tree.insert({5, 13});
31+
auto firstInterval = types::interval_type{0, 16};
32+
auto secondInterval = types::interval_type{5, 13};
33+
34+
tree.insert(firstInterval);
35+
tree.insert(secondInterval);
3336

3437
EXPECT_EQ(tree.size(), 2);
38+
39+
EXPECT_EQ(*tree.begin(), firstInterval);
40+
EXPECT_EQ(*(++tree.begin()), secondInterval);
3541
}

tests/interval_tests.hpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ TEST_F(IntervalTests, TestLimits)
8181
EXPECT_EQ(ival.high(), std::numeric_limits<types::value_type>::max());
8282
}
8383

84+
TEST_F(IntervalTests, TestIntervalSize)
85+
{
86+
auto ival = types::interval_type{0, 5};
87+
EXPECT_EQ(ival.size(), 5);
88+
89+
auto ival2 = types::interval_type{-21, 5};
90+
EXPECT_EQ(ival2.size(), 26);
91+
92+
auto ival3 = types::interval_type{-20, -5};
93+
EXPECT_EQ(ival3.size(), 15);
94+
95+
auto ival4 = types::interval_type{100, 125};
96+
EXPECT_EQ(ival4.size(), 25);
97+
}
98+
8499
TEST_F(OverlapTests, ShallOverlapItself)
85100
{
86101
auto base = types::interval_type{0, 5};
@@ -212,7 +227,34 @@ TEST_F(ContainmentTests, ExpectIntervalNotWithinOther)
212227
TEST_F(DistanceTests, DistanceIsZeroOnOverlap)
213228
{
214229
auto base = types::interval_type{-35, 96};
215-
216230
auto other = types::interval_type{-20, 600};
217231
EXPECT_EQ(base - other, 0);
218232
}
233+
234+
TEST_F(DistanceTests, DistanceLeftSide)
235+
{
236+
auto base = types::interval_type{5, 10};
237+
auto other = types::interval_type{0, 1};
238+
EXPECT_EQ(base - other, 4);
239+
}
240+
241+
TEST_F(DistanceTests, DistanceRightSide)
242+
{
243+
auto base = types::interval_type{5, 10};
244+
auto other = types::interval_type{15, 18};
245+
EXPECT_EQ(base - other, 5);
246+
}
247+
248+
TEST_F(DistanceTests, DistanceAdjacent)
249+
{
250+
auto base = types::interval_type{5, 10};
251+
auto other = types::interval_type{10, 18};
252+
EXPECT_EQ(base - other, 0);
253+
}
254+
255+
TEST_F(DistanceTests, DistanceAdjacent2)
256+
{
257+
auto base = types::interval_type{5, 10};
258+
auto other = types::interval_type{0, 5};
259+
EXPECT_EQ(base - other, 0);
260+
}

0 commit comments

Comments
 (0)