diff options
| author | chenzizhan <[email protected]> | 2023-09-25 15:33:41 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2023-09-25 15:33:41 +0800 |
| commit | 010bbf32d7f529149d7240e34c3474315c2035a2 (patch) | |
| tree | 6996bf2391366be68862fb288c06428cbb63dae9 /test/unit_test_cell_manager.cpp | |
| parent | 0a6d05492652a46ebdb0706b23e52ce908cda5da (diff) | |
fix ci
Diffstat (limited to 'test/unit_test_cell_manager.cpp')
| -rw-r--r-- | test/unit_test_cell_manager.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/unit_test_cell_manager.cpp b/test/unit_test_cell_manager.cpp index 375d36d..bffd440 100644 --- a/test/unit_test_cell_manager.cpp +++ b/test/unit_test_cell_manager.cpp @@ -683,6 +683,51 @@ TEST(unit_test_cell_manager, add_after_reset_and_ensure_performance_improvement) } } +TEST(unit_test_cell_manager, reset_once_and_query_topk) +{ + const int TEST_ROUND = 10; + struct cell_manager *cm = cell_manager_new(SAMPLING_MODE_TOPK, TEST_ROUND); + + vector<struct tag_hash_key *> keys; + for (int i = 0; i < TEST_ROUND; i++) + { + struct tag_hash_key *key = test_gen_tag_key("key", i); + keys.push_back(key); + } + for (int i = 0; i < TEST_ROUND; i++) { + int cell_id = cell_manager_add_cell(cm, keys[i]); + EXPECT_EQ(cell_id, i); + } + + cell_manager_reset(cm); + for (int i = 0; i < TEST_ROUND; i++) { + EXPECT_EQ(cell_manager_find(cm, keys[i]), -1); + EXPECT_TRUE(cell_manager_get_tag_by_cell_id(cm, i) == NULL); + } + int array_len = 0; + cell_manager_dump(cm, &array_len); + EXPECT_EQ(array_len, 0); + + // do it again, to see the effect of reset on a recovered cell_manager(instead of which just newed) + for (int i = 0; i < TEST_ROUND; i++) { + int cell_id = cell_manager_add_cell(cm, keys[i]); + EXPECT_EQ(cell_id, i); + } + cell_manager_reset(cm); + for (int i = 0; i < TEST_ROUND; i++) { + EXPECT_EQ(cell_manager_find(cm, keys[i]), -1); + EXPECT_TRUE(cell_manager_get_tag_by_cell_id(cm, i) == NULL); + EXPECT_EQ(cell_manager_get_count_by_tag(cm, keys[i]), 0); + } + cell_manager_dump(cm, &array_len); + EXPECT_EQ(array_len, 0); + + cell_manager_free(cm); + for (int i = 0; i < TEST_ROUND; i++) { + tag_hash_key_free(keys[i]); + } +} + int main(int argc, char *argv[]) { testing::InitGoogleTest(&argc, argv); |
