aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/cache/ut
diff options
context:
space:
mode:
authorkikht <kikht@yandex-team.ru>2022-02-10 16:45:14 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:14 +0300
commit194cae0e8855b11be2005e1eff12c660c3ee9774 (patch)
treeed29c437b616690880c017855ebe0be34fdf81a2 /library/cpp/cache/ut
parent49116032d905455a7b1c994e4a696afc885c1e71 (diff)
downloadydb-194cae0e8855b11be2005e1eff12c660c3ee9774.tar.gz
Restoring authorship annotation for <kikht@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/cache/ut')
-rw-r--r--library/cpp/cache/ut/cache_ut.cpp278
1 files changed, 139 insertions, 139 deletions
diff --git a/library/cpp/cache/ut/cache_ut.cpp b/library/cpp/cache/ut/cache_ut.cpp
index 329872cfde..87601ae3d6 100644
--- a/library/cpp/cache/ut/cache_ut.cpp
+++ b/library/cpp/cache/ut/cache_ut.cpp
@@ -172,145 +172,145 @@ Y_UNIT_TEST_SUITE(TCacheTest) {
UNIT_ASSERT(s.Find(3) == s.End());
}
- Y_UNIT_TEST(LRUSetMaxSizeTest) {
- typedef TLRUCache<int, TString> TCache;
- TCache s(2); // size 2
- s.Insert(1, "abcd");
- s.Insert(2, "efgh");
- s.Insert(3, "ijkl");
- UNIT_ASSERT(s.GetOldest() == "efgh");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) != s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
-
- // Increasing size should not change anything
- s.SetMaxSize(3);
- UNIT_ASSERT(s.GetOldest() == "efgh");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) != s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
-
- // And we should be able to add fit more entries
- s.Insert(4, "mnop");
- s.Insert(5, "qrst");
- UNIT_ASSERT(s.GetOldest() == "ijkl");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
- UNIT_ASSERT(s.Find(4) != s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
-
- // Decreasing size should remove oldest entries
- s.SetMaxSize(2);
- UNIT_ASSERT(s.GetOldest() == "mnop");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) == s.End());
- UNIT_ASSERT(s.Find(4) != s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
-
- // Ano no more entries will fit
- s.Insert(6, "uvwx");
- UNIT_ASSERT(s.GetOldest() == "qrst");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) == s.End());
- UNIT_ASSERT(s.Find(4) == s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
- UNIT_ASSERT(s.Find(6) != s.End());
- }
-
- Y_UNIT_TEST(LWSetMaxSizeTest) {
- typedef TLWCache<int, TString, size_t, TStrokaWeighter> TCache;
- TCache s(2); // size 2
- s.Insert(1, "a");
- s.Insert(2, "aa");
- s.Insert(3, "aaa");
- UNIT_ASSERT(s.GetLightest() == "aa");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) != s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
-
- // Increasing size should not change anything
- s.SetMaxSize(3);
- UNIT_ASSERT(s.GetLightest() == "aa");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) != s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
-
- // And we should be able to add fit more entries
- s.Insert(4, "aaaa");
- s.Insert(5, "aaaaa");
- UNIT_ASSERT(s.GetLightest() == "aaa");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
- UNIT_ASSERT(s.Find(4) != s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
-
- // Decreasing size should remove oldest entries
- s.SetMaxSize(2);
- UNIT_ASSERT(s.GetLightest() == "aaaa");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) == s.End());
- UNIT_ASSERT(s.Find(4) != s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
-
- // Ano no more entries will fit
- s.Insert(6, "aaaaaa");
- UNIT_ASSERT(s.GetLightest() == "aaaaa");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) == s.End());
- UNIT_ASSERT(s.Find(4) == s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
- UNIT_ASSERT(s.Find(6) != s.End());
- }
-
- Y_UNIT_TEST(LFUSetMaxSizeTest) {
- typedef TLFUCache<int, TString> TCache;
- TCache s(2); // size 2
- s.Insert(1, "abcd");
- s.Insert(2, "efgh");
- s.Insert(3, "ijkl");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) != s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
-
- // Increasing size should not change anything
- s.SetMaxSize(3);
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) != s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
-
- // And we should be able to add fit more entries
- s.Insert(4, "mnop");
- s.Insert(5, "qrst");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
- UNIT_ASSERT(s.Find(4) != s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
-
- // Decreasing size should remove oldest entries
- s.SetMaxSize(2);
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
- UNIT_ASSERT(s.Find(4) == s.End());
- UNIT_ASSERT(s.Find(5) != s.End());
-
- // Ano no more entries will fit
- s.Insert(6, "uvwx");
- UNIT_ASSERT(s.Find(1) == s.End());
- UNIT_ASSERT(s.Find(2) == s.End());
- UNIT_ASSERT(s.Find(3) != s.End());
- UNIT_ASSERT(s.Find(4) == s.End());
- UNIT_ASSERT(s.Find(5) == s.End());
- UNIT_ASSERT(s.Find(6) != s.End());
- }
-
+ Y_UNIT_TEST(LRUSetMaxSizeTest) {
+ typedef TLRUCache<int, TString> TCache;
+ TCache s(2); // size 2
+ s.Insert(1, "abcd");
+ s.Insert(2, "efgh");
+ s.Insert(3, "ijkl");
+ UNIT_ASSERT(s.GetOldest() == "efgh");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) != s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+
+ // Increasing size should not change anything
+ s.SetMaxSize(3);
+ UNIT_ASSERT(s.GetOldest() == "efgh");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) != s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+
+ // And we should be able to add fit more entries
+ s.Insert(4, "mnop");
+ s.Insert(5, "qrst");
+ UNIT_ASSERT(s.GetOldest() == "ijkl");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+ UNIT_ASSERT(s.Find(4) != s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+
+ // Decreasing size should remove oldest entries
+ s.SetMaxSize(2);
+ UNIT_ASSERT(s.GetOldest() == "mnop");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) == s.End());
+ UNIT_ASSERT(s.Find(4) != s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+
+ // Ano no more entries will fit
+ s.Insert(6, "uvwx");
+ UNIT_ASSERT(s.GetOldest() == "qrst");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) == s.End());
+ UNIT_ASSERT(s.Find(4) == s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+ UNIT_ASSERT(s.Find(6) != s.End());
+ }
+
+ Y_UNIT_TEST(LWSetMaxSizeTest) {
+ typedef TLWCache<int, TString, size_t, TStrokaWeighter> TCache;
+ TCache s(2); // size 2
+ s.Insert(1, "a");
+ s.Insert(2, "aa");
+ s.Insert(3, "aaa");
+ UNIT_ASSERT(s.GetLightest() == "aa");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) != s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+
+ // Increasing size should not change anything
+ s.SetMaxSize(3);
+ UNIT_ASSERT(s.GetLightest() == "aa");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) != s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+
+ // And we should be able to add fit more entries
+ s.Insert(4, "aaaa");
+ s.Insert(5, "aaaaa");
+ UNIT_ASSERT(s.GetLightest() == "aaa");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+ UNIT_ASSERT(s.Find(4) != s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+
+ // Decreasing size should remove oldest entries
+ s.SetMaxSize(2);
+ UNIT_ASSERT(s.GetLightest() == "aaaa");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) == s.End());
+ UNIT_ASSERT(s.Find(4) != s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+
+ // Ano no more entries will fit
+ s.Insert(6, "aaaaaa");
+ UNIT_ASSERT(s.GetLightest() == "aaaaa");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) == s.End());
+ UNIT_ASSERT(s.Find(4) == s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+ UNIT_ASSERT(s.Find(6) != s.End());
+ }
+
+ Y_UNIT_TEST(LFUSetMaxSizeTest) {
+ typedef TLFUCache<int, TString> TCache;
+ TCache s(2); // size 2
+ s.Insert(1, "abcd");
+ s.Insert(2, "efgh");
+ s.Insert(3, "ijkl");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) != s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+
+ // Increasing size should not change anything
+ s.SetMaxSize(3);
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) != s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+
+ // And we should be able to add fit more entries
+ s.Insert(4, "mnop");
+ s.Insert(5, "qrst");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+ UNIT_ASSERT(s.Find(4) != s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+
+ // Decreasing size should remove oldest entries
+ s.SetMaxSize(2);
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+ UNIT_ASSERT(s.Find(4) == s.End());
+ UNIT_ASSERT(s.Find(5) != s.End());
+
+ // Ano no more entries will fit
+ s.Insert(6, "uvwx");
+ UNIT_ASSERT(s.Find(1) == s.End());
+ UNIT_ASSERT(s.Find(2) == s.End());
+ UNIT_ASSERT(s.Find(3) != s.End());
+ UNIT_ASSERT(s.Find(4) == s.End());
+ UNIT_ASSERT(s.Find(5) == s.End());
+ UNIT_ASSERT(s.Find(6) != s.End());
+ }
+
Y_UNIT_TEST(MultiCacheTest) {
typedef TLRUCache<int, TString> TCache;
TCache s(3, true);