From 596f77898e8967061a13a8b75b39c3aaffd94932 Mon Sep 17 00:00:00 2001 From: Harpreet Sangar Date: Tue, 30 May 2023 09:56:09 +0530 Subject: [PATCH] Add test case. --- src/numeric_range_trie.cpp | 4 ++++ test/numeric_range_trie_test.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/numeric_range_trie.cpp b/src/numeric_range_trie.cpp index 254bffd5..be0c7f2c 100644 --- a/src/numeric_range_trie.cpp +++ b/src/numeric_range_trie.cpp @@ -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 search_range(-32768, true, 32768, true, ids, ids_length); + trie->search_range(32768, true, -32768, true, ids, ids_length); std::unique_ptr 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]);