diff options
author | tldr <tldr@yandex-team.ru> | 2022-02-10 16:50:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:18 +0300 |
commit | 42d219fbd63ee173b0cb7db1b26a3ec615f0bb71 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/cache/ut | |
parent | fb217752f4b5a81abe9df05e38c5a71d080fc2a8 (diff) | |
download | ydb-42d219fbd63ee173b0cb7db1b26a3ec615f0bb71.tar.gz |
Restoring authorship annotation for <tldr@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/cache/ut')
-rw-r--r-- | library/cpp/cache/ut/cache_ut.cpp | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/library/cpp/cache/ut/cache_ut.cpp b/library/cpp/cache/ut/cache_ut.cpp index 886afecb88..329872cfde 100644 --- a/library/cpp/cache/ut/cache_ut.cpp +++ b/library/cpp/cache/ut/cache_ut.cpp @@ -29,42 +29,42 @@ Y_UNIT_TEST_SUITE(TCacheTest) { UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); } - Y_UNIT_TEST(LRUListWeightedTest) { - typedef TLRUList<int, TString, size_t (*)(const TString&)> TListType; - TListType list(7, [](auto& string) { - return string.size(); - }); - - TListType::TItem x1(1, "ttt"); - list.Insert(&x1); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - - TListType::TItem x2(2, "yyy"); - list.Insert(&x2); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - - list.Promote(list.GetOldest()); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 2); - - TListType::TItem x3(3, "zzz"); - list.Insert(&x3); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); - - TListType::TItem x4(4, "longlong"); - list.Insert(&x4); - while (list.RemoveIfOverflown()) { - } - UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 4); - } - + Y_UNIT_TEST(LRUListWeightedTest) { + typedef TLRUList<int, TString, size_t (*)(const TString&)> TListType; + TListType list(7, [](auto& string) { + return string.size(); + }); + + TListType::TItem x1(1, "ttt"); + list.Insert(&x1); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); + + TListType::TItem x2(2, "yyy"); + list.Insert(&x2); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); + + list.Promote(list.GetOldest()); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 2); + + TListType::TItem x3(3, "zzz"); + list.Insert(&x3); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 1); + + TListType::TItem x4(4, "longlong"); + list.Insert(&x4); + while (list.RemoveIfOverflown()) { + } + UNIT_ASSERT_EQUAL(list.GetOldest()->Key, 4); + } + Y_UNIT_TEST(LFUListTest) { typedef TLFUList<int, TString> TListType; TListType list(2); @@ -141,37 +141,37 @@ Y_UNIT_TEST_SUITE(TCacheTest) { UNIT_ASSERT(s.Find(3) == s.End()); } - Y_UNIT_TEST(LRUWithCustomSizeProviderTest) { - typedef TLRUCache<int, TString, TNoopDelete, size_t(*)(const TString&)> TCache; - TCache s(10, false, [](auto& string) { return string.size(); }); // size 10 - s.Insert(1, "abcd"); - UNIT_ASSERT(s.Find(1) != s.End()); - UNIT_ASSERT_EQUAL(*s.Find(1), "abcd"); - s.Insert(2, "defg"); - UNIT_ASSERT(s.GetOldest() == "abcd"); - s.Insert(3, "2c"); - UNIT_ASSERT(s.GetOldest() == "abcd"); - s.Insert(4, "hjkl"); - UNIT_ASSERT(s.GetOldest() == "defg"); - // key 1 will be deleted - UNIT_ASSERT(s.Find(1) == s.End()); - UNIT_ASSERT(s.Find(2) != s.End()); - UNIT_ASSERT(*s.Find(2) == "defg"); - UNIT_ASSERT(s.Find(3) != s.End()); - UNIT_ASSERT(*s.Find(3) == "2c"); - UNIT_ASSERT(s.Find(4) != s.End()); - UNIT_ASSERT(*s.Find(4) == "hjkl"); - - UNIT_ASSERT(!s.Insert(3, "abcd")); - UNIT_ASSERT(*s.Find(3) == "2c"); - s.Update(3, "abcd"); - UNIT_ASSERT(*s.Find(3) == "abcd"); - - TCache::TIterator it = s.Find(3); - s.Erase(it); - UNIT_ASSERT(s.Find(3) == s.End()); - } - + Y_UNIT_TEST(LRUWithCustomSizeProviderTest) { + typedef TLRUCache<int, TString, TNoopDelete, size_t(*)(const TString&)> TCache; + TCache s(10, false, [](auto& string) { return string.size(); }); // size 10 + s.Insert(1, "abcd"); + UNIT_ASSERT(s.Find(1) != s.End()); + UNIT_ASSERT_EQUAL(*s.Find(1), "abcd"); + s.Insert(2, "defg"); + UNIT_ASSERT(s.GetOldest() == "abcd"); + s.Insert(3, "2c"); + UNIT_ASSERT(s.GetOldest() == "abcd"); + s.Insert(4, "hjkl"); + UNIT_ASSERT(s.GetOldest() == "defg"); + // key 1 will be deleted + UNIT_ASSERT(s.Find(1) == s.End()); + UNIT_ASSERT(s.Find(2) != s.End()); + UNIT_ASSERT(*s.Find(2) == "defg"); + UNIT_ASSERT(s.Find(3) != s.End()); + UNIT_ASSERT(*s.Find(3) == "2c"); + UNIT_ASSERT(s.Find(4) != s.End()); + UNIT_ASSERT(*s.Find(4) == "hjkl"); + + UNIT_ASSERT(!s.Insert(3, "abcd")); + UNIT_ASSERT(*s.Find(3) == "2c"); + s.Update(3, "abcd"); + UNIT_ASSERT(*s.Find(3) == "abcd"); + + TCache::TIterator it = s.Find(3); + s.Erase(it); + UNIT_ASSERT(s.Find(3) == s.End()); + } + Y_UNIT_TEST(LRUSetMaxSizeTest) { typedef TLRUCache<int, TString> TCache; TCache s(2); // size 2 |