aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/encode/buffered/string_pool_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/monlib/encode/buffered/string_pool_ut.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/monlib/encode/buffered/string_pool_ut.cpp')
-rw-r--r--library/cpp/monlib/encode/buffered/string_pool_ut.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/library/cpp/monlib/encode/buffered/string_pool_ut.cpp b/library/cpp/monlib/encode/buffered/string_pool_ut.cpp
new file mode 100644
index 0000000000..9fc3421d0b
--- /dev/null
+++ b/library/cpp/monlib/encode/buffered/string_pool_ut.cpp
@@ -0,0 +1,84 @@
+#include "string_pool.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+using namespace NMonitoring;
+
+Y_UNIT_TEST_SUITE(TStringPoolTest) {
+ Y_UNIT_TEST(PutIfAbsent) {
+ TStringPoolBuilder strPool;
+ strPool.SetSorted(true);
+
+ auto* h1 = strPool.PutIfAbsent("one");
+ auto* h2 = strPool.PutIfAbsent("two");
+ auto* h3 = strPool.PutIfAbsent("two");
+ UNIT_ASSERT(h1 != h2);
+ UNIT_ASSERT(h2 == h3);
+
+ UNIT_ASSERT_VALUES_EQUAL(h1->Frequency, 1);
+ UNIT_ASSERT_VALUES_EQUAL(h1->Index, 0);
+
+ UNIT_ASSERT_VALUES_EQUAL(h2->Frequency, 2);
+ UNIT_ASSERT_VALUES_EQUAL(h2->Index, 1);
+
+ UNIT_ASSERT_VALUES_EQUAL(strPool.BytesSize(), 6);
+ UNIT_ASSERT_VALUES_EQUAL(strPool.Count(), 2);
+ }
+
+ Y_UNIT_TEST(SortByFrequency) {
+ TStringPoolBuilder strPool;
+ strPool.SetSorted(true);
+
+ auto* h1 = strPool.PutIfAbsent("one");
+ auto* h2 = strPool.PutIfAbsent("two");
+ auto* h3 = strPool.PutIfAbsent("two");
+ UNIT_ASSERT(h1 != h2);
+ UNIT_ASSERT(h2 == h3);
+
+ strPool.Build();
+
+ UNIT_ASSERT_VALUES_EQUAL(h1->Frequency, 1);
+ UNIT_ASSERT_VALUES_EQUAL(h1->Index, 1);
+
+ UNIT_ASSERT_VALUES_EQUAL(h2->Frequency, 2);
+ UNIT_ASSERT_VALUES_EQUAL(h2->Index, 0);
+
+ UNIT_ASSERT_VALUES_EQUAL(strPool.BytesSize(), 6);
+ UNIT_ASSERT_VALUES_EQUAL(strPool.Count(), 2);
+ }
+
+ Y_UNIT_TEST(ForEach) {
+ TStringPoolBuilder strPool;
+ strPool.SetSorted(true);
+
+ strPool.PutIfAbsent("one");
+ strPool.PutIfAbsent("two");
+ strPool.PutIfAbsent("two");
+ strPool.PutIfAbsent("three");
+ strPool.PutIfAbsent("three");
+ strPool.PutIfAbsent("three");
+
+ UNIT_ASSERT_VALUES_EQUAL(strPool.BytesSize(), 11);
+ UNIT_ASSERT_VALUES_EQUAL(strPool.Count(), 3);
+
+ strPool.Build();
+
+ TVector<TString> strings;
+ TVector<ui32> indexes;
+ TVector<ui32> frequences;
+ strPool.ForEach([&](TStringBuf str, ui32 index, ui32 freq) {
+ strings.emplace_back(str);
+ indexes.push_back(index);
+ frequences.push_back(freq);
+ });
+
+ TVector<TString> expectedStrings = {"three", "two", "one"};
+ UNIT_ASSERT_EQUAL(strings, expectedStrings);
+
+ TVector<ui32> expectedIndexes = {0, 1, 2};
+ UNIT_ASSERT_EQUAL(indexes, expectedIndexes);
+
+ TVector<ui32> expectedFrequences = {3, 2, 1};
+ UNIT_ASSERT_EQUAL(frequences, expectedFrequences);
+ }
+}