mirror of
https://github.com/typesense/typesense.git
synced 2025-05-25 00:01:18 +08:00
Add MultivalueData
test.
This commit is contained in:
parent
7ab7908f92
commit
377665b671
@ -357,7 +357,106 @@ TEST_F(NumericRangeTrieTest, SearchLesser) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(NumericRangeTrieTest, Validation) {
|
||||
TEST_F(NumericRangeTrieTest, MultivalueData) {
|
||||
auto trie = new NumericTrie();
|
||||
std::unique_ptr<NumericTrie> trie_guard(trie);
|
||||
std::vector<std::pair<int32_t, uint32_t>> pairs = {
|
||||
{-0x202020, 32},
|
||||
{-32768, 5},
|
||||
{-32768, 8},
|
||||
{-24576, 32},
|
||||
{-16384, 35},
|
||||
{-8192, 43},
|
||||
{0, 43},
|
||||
{0, 49},
|
||||
{1, 8},
|
||||
{256, 91},
|
||||
{8192, 49},
|
||||
{16384, 56},
|
||||
{24576, 58},
|
||||
{32768, 91},
|
||||
{0x202020, 35},
|
||||
};
|
||||
|
||||
for (auto const& pair: pairs) {
|
||||
trie->insert(pair.first, pair.second);
|
||||
}
|
||||
|
||||
uint32_t* ids = nullptr;
|
||||
uint32_t ids_length = 0;
|
||||
|
||||
trie->search_lesser(0, false, ids, ids_length);
|
||||
std::unique_ptr<uint32_t[]> ids_guard(ids);
|
||||
|
||||
std::vector<uint32_t> expected = {5, 8, 32, 35, 43};
|
||||
|
||||
ASSERT_EQ(5, ids_length);
|
||||
for (uint32_t i = 0; i < ids_length; i++) {
|
||||
ASSERT_EQ(expected[i], ids[i]);
|
||||
}
|
||||
|
||||
trie->search_lesser(-16380, false, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(4, ids_length);
|
||||
|
||||
expected = {5, 8, 32, 35};
|
||||
for (uint32_t i = 0; i < ids_length; i++) {
|
||||
ASSERT_EQ(expected[i], ids[i]);
|
||||
}
|
||||
|
||||
trie->search_lesser(16384, false, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(7, ids_length);
|
||||
|
||||
expected = {5, 8, 32, 35, 43, 49, 91};
|
||||
for (uint32_t i = 0; i < ids_length; i++) {
|
||||
ASSERT_EQ(expected[i], ids[i]);
|
||||
}
|
||||
|
||||
trie->search_greater(0, true, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(7, ids_length);
|
||||
|
||||
expected = {8, 35, 43, 49, 56, 58, 91};
|
||||
for (uint32_t i = 0; i < ids_length; i++) {
|
||||
ASSERT_EQ(expected[i], ids[i]);
|
||||
}
|
||||
|
||||
trie->search_greater(256, true, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(5, ids_length);
|
||||
|
||||
expected = {35, 49, 56, 58, 91};
|
||||
for (uint32_t i = 0; i < ids_length; i++) {
|
||||
ASSERT_EQ(expected[i], ids[i]);
|
||||
}
|
||||
|
||||
trie->search_greater(-32768, true, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(9, ids_length);
|
||||
|
||||
expected = {5, 8, 32, 35, 43, 49, 56, 58, 91};
|
||||
for (uint32_t i = 0; i < ids_length; i++) {
|
||||
ASSERT_EQ(expected[i], ids[i]);
|
||||
}
|
||||
|
||||
trie->search_range(-32768, true, 0, true, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(6, ids_length);
|
||||
|
||||
expected = {5, 8, 32, 35, 43, 49};
|
||||
for (uint32_t i = 0; i < ids_length; i++) {
|
||||
ASSERT_EQ(expected[i], ids[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(NumericRangeTrieTest, EmptyTrieOperations) {
|
||||
auto trie = new NumericTrie();
|
||||
std::unique_ptr<NumericTrie> trie_guard(trie);
|
||||
|
||||
@ -369,6 +468,16 @@ TEST_F(NumericRangeTrieTest, Validation) {
|
||||
|
||||
ASSERT_EQ(0, ids_length);
|
||||
|
||||
trie->search_range(-32768, true, -1, true, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(0, ids_length);
|
||||
|
||||
trie->search_range(1, true, 32768, true, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
ASSERT_EQ(0, ids_length);
|
||||
|
||||
trie->search_greater(0, true, ids, ids_length);
|
||||
ids_guard.reset(ids);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user