Add test case.

This commit is contained in:
Harpreet Sangar 2023-05-30 09:56:09 +05:30
parent 64ec856097
commit 596f77898e
2 changed files with 10 additions and 1 deletions

View File

@ -20,6 +20,10 @@ void NumericTrie::insert(const int32_t& value, const uint32_t& seq_id) {
void NumericTrie::search_range(const int32_t& low, const bool& low_inclusive,
const int32_t& high, const bool& high_inclusive,
uint32_t*& ids, uint32_t& ids_length) {
if (low >= high) {
return;
}
if (low < 0 && high >= 0) {
// Have to combine the results of >low from negative_trie and <high from positive_trie

View File

@ -30,9 +30,14 @@ TEST_F(NumericRangeTrieTest, SearchRange) {
uint32_t* ids = nullptr;
uint32_t ids_length = 0;
trie->search_range(-32768, true, 32768, true, ids, ids_length);
trie->search_range(32768, true, -32768, true, ids, ids_length);
std::unique_ptr<uint32_t[]> ids_guard(ids);
ASSERT_EQ(0, ids_length);
trie->search_range(-32768, true, 32768, true, ids, ids_length);
ids_guard.reset(ids);
ASSERT_EQ(pairs.size(), ids_length);
for (uint32_t i = 0; i < pairs.size(); i++) {
ASSERT_EQ(pairs[i].second, ids[i]);