Skip to content

Commit 663a928

Browse files
committed
Added test for join only custom interval.
1 parent ae79195 commit 663a928

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/custom_interval_tests.hpp

+36
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ struct custom_interval : public lib_interval_tree::interval<numerical_type, inte
5353
}
5454
};
5555

56+
struct minimal_custom_interval : public lib_interval_tree::interval<int, lib_interval_tree::closed>
57+
{
58+
using lib_interval_tree::interval<int, lib_interval_tree::closed>::interval;
59+
60+
std::function<minimal_custom_interval(minimal_custom_interval const& other)> on_join;
61+
minimal_custom_interval join(minimal_custom_interval const& other) const
62+
{
63+
if (on_join)
64+
return on_join(other);
65+
return {std::min(low_, other.low_), std::max(high_, other.high_)};
66+
}
67+
};
68+
5669
TEST_F(CustomIntervalTests, CanInsertCustomIntervalJoined)
5770
{
5871
lib_interval_tree::interval_tree<custom_interval<int>> tree;
@@ -116,4 +129,27 @@ TEST_F(CustomIntervalTests, CustomOverlapsExclusiveIvalIsCalled)
116129
tree.insert_overlap(ival2, true);
117130

118131
EXPECT_TRUE(overlaps_exclusive_ival_called);
132+
}
133+
134+
TEST_F(CustomIntervalTests, CanUseMinimalCustomInterval)
135+
{
136+
lib_interval_tree::interval_tree<minimal_custom_interval> tree;
137+
tree.insert({0, 5});
138+
tree.insert_overlap({4, 10});
139+
tree.erase(tree.begin());
140+
141+
EXPECT_EQ(tree.size(), 0);
142+
143+
tree.insert({0, 5});
144+
tree.insert({7, 10});
145+
auto iter = tree.find({0, 5});
146+
ASSERT_NE(iter, tree.end());
147+
EXPECT_EQ(iter->low(), 0);
148+
EXPECT_EQ(iter->high(), 5);
149+
150+
tree.deoverlap();
151+
auto iter2 = tree.overlap_find({8, 12});
152+
ASSERT_NE(iter2, tree.end());
153+
EXPECT_EQ(iter2->low(), 7);
154+
EXPECT_EQ(iter2->high(), 10);
119155
}

0 commit comments

Comments
 (0)