Skip to content

Commit 7e6fa11

Browse files
committed
Fixed merge issue and added simple tests.
1 parent 05f9302 commit 7e6fa11

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/find_tests.hpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class FindTests
77
using types = IntervalTypes <int>;
88
protected:
99
IntervalTypes <int>::tree_type tree;
10+
std::default_random_engine gen;
11+
std::uniform_int_distribution <int> distSmall{-500, 500};
12+
std::uniform_int_distribution <int> distLarge{-50000, 50000};
1013
};
1114

1215
TEST_F(FindTests, WillReturnEndIfTreeIsEmpty)
@@ -78,3 +81,57 @@ TEST_F(FindTests, WillFindAllCanExitPreemptively)
7881
EXPECT_EQ(findCount, 3);
7982
}
8083

84+
TEST_F(FindTests, CanFindAllElementsBack)
85+
{
86+
constexpr int amount = 10'000;
87+
88+
std::vector <decltype(tree)::interval_type> intervals;
89+
intervals.reserve(amount);
90+
for (int i = 0; i != amount; ++i)
91+
{
92+
const auto interval = lib_interval_tree::make_safe_interval(distLarge(gen), distLarge(gen));
93+
intervals.emplace_back(interval);
94+
tree.insert(interval);
95+
}
96+
for (auto const& ival : intervals)
97+
{
98+
ASSERT_NE(tree.find(ival), std::end(tree));
99+
}
100+
}
101+
102+
TEST_F(FindTests, CanFindAllElementsBackInStrictlyAscendingNonOverlappingIntervals)
103+
{
104+
constexpr int amount = 10'000;
105+
106+
std::vector <decltype(tree)::interval_type> intervals;
107+
intervals.reserve(amount);
108+
for (int i = 0; i != amount; ++i)
109+
{
110+
const auto interval = lib_interval_tree::make_safe_interval(i * 2, i * 2 + 1);
111+
intervals.emplace_back(interval);
112+
tree.insert(interval);
113+
}
114+
for (auto const& ival : intervals)
115+
{
116+
ASSERT_NE(tree.find(ival), std::end(tree));
117+
}
118+
}
119+
120+
TEST_F(FindTests, CanFindAllElementsBackInStrictlyAscendingOverlappingIntervals)
121+
{
122+
constexpr int amount = 10'000;
123+
124+
std::vector <decltype(tree)::interval_type> intervals;
125+
intervals.reserve(amount);
126+
for (int i = 0; i != amount; ++i)
127+
{
128+
const auto interval = lib_interval_tree::make_safe_interval(i - 1, i + 1);
129+
intervals.emplace_back(interval);
130+
tree.insert(interval);
131+
}
132+
for (auto const& ival : intervals)
133+
{
134+
ASSERT_NE(tree.find(ival), std::end(tree));
135+
}
136+
}
137+

0 commit comments

Comments
 (0)