diff options
author | udovichenko-r <udovichenko-r@yandex-team.ru> | 2022-02-10 16:49:21 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:21 +0300 |
commit | d7e4eaec9d325e188dabb3eb1949a32a5229e9ce (patch) | |
tree | 75f143caa4e1e35b760846b22310ede3212d7f63 /library/cpp/containers/comptrie/comptrie_ut.cpp | |
parent | 027f7b7f6644e258a5840869b9b82c79e1ebeee0 (diff) | |
download | ydb-d7e4eaec9d325e188dabb3eb1949a32a5229e9ce.tar.gz |
Restoring authorship annotation for <udovichenko-r@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/containers/comptrie/comptrie_ut.cpp')
-rw-r--r-- | library/cpp/containers/comptrie/comptrie_ut.cpp | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/library/cpp/containers/comptrie/comptrie_ut.cpp b/library/cpp/containers/comptrie/comptrie_ut.cpp index 74bee09b5d..ea7df5c59d 100644 --- a/library/cpp/containers/comptrie/comptrie_ut.cpp +++ b/library/cpp/containers/comptrie/comptrie_ut.cpp @@ -96,7 +96,7 @@ private: UNIT_TEST(TestSearchIterChar); UNIT_TEST(TestSearchIterWchar); UNIT_TEST(TestSearchIterWchar32) - + UNIT_TEST(TestCopyAndAssignment); UNIT_TEST(TestFirstSymbolIterator8); @@ -152,9 +152,9 @@ private: template <class TContainer> void TestTrieWithContainers(const TVector<TUtf16String>& keys, const TVector<TContainer>& sampleData, TString methodName); - template <typename TChar> - void TestSearchIterImpl(); - + template <typename TChar> + void TestSearchIterImpl(); + template <class TTrie> void TestFirstSymbolIteratorForTrie(const TTrie& trie, const TStringBuf& narrowAnswers); @@ -230,8 +230,8 @@ public: void TestEmptyValueOutOfOrder(); void TestFindLongestPrefixWithEmptyValue(); - void TestSearchIterChar(); - void TestSearchIterWchar(); + void TestSearchIterChar(); + void TestSearchIterWchar(); void TestSearchIterWchar32(); void TestCopyAndAssignment(); @@ -1292,21 +1292,21 @@ void TCompactTrieTest::TestFindLongestPrefixWithEmptyValue() { UNIT_ASSERT(value == 31415); } } - -template <typename TChar> -struct TConvertKey { + +template <typename TChar> +struct TConvertKey { static inline TString Convert(const TStringBuf& key) { return ToString(key); - } -}; - -template <> -struct TConvertKey<wchar16> { + } +}; + +template <> +struct TConvertKey<wchar16> { static inline TUtf16String Convert(const TStringBuf& key) { - return UTF8ToWide(key); - } -}; - + return UTF8ToWide(key); + } +}; + template <> struct TConvertKey<wchar32> { static inline TUtf32String Convert(const TStringBuf& key) { @@ -1314,62 +1314,62 @@ struct TConvertKey<wchar32> { } }; -template <class TSearchIter, class TKeyBuf> -static void MoveIter(TSearchIter& iter, const TKeyBuf& key) { - for (size_t i = 0; i < key.length(); ++i) { - UNIT_ASSERT(iter.Advance(key[i])); - } -} - -template <typename TChar> -void TCompactTrieTest::TestSearchIterImpl() { - TBufferOutput buffer; - { - TCompactTrieBuilder<TChar, ui32> builder; - TStringBuf data[] = { +template <class TSearchIter, class TKeyBuf> +static void MoveIter(TSearchIter& iter, const TKeyBuf& key) { + for (size_t i = 0; i < key.length(); ++i) { + UNIT_ASSERT(iter.Advance(key[i])); + } +} + +template <typename TChar> +void TCompactTrieTest::TestSearchIterImpl() { + TBufferOutput buffer; + { + TCompactTrieBuilder<TChar, ui32> builder; + TStringBuf data[] = { TStringBuf("abaab"), TStringBuf("abcdef"), TStringBuf("abbbc"), TStringBuf("bdfaa"), - }; + }; for (size_t i = 0; i < Y_ARRAY_SIZE(data); ++i) { - builder.Add(TConvertKey<TChar>::Convert(data[i]), i + 1); - } - builder.Save(buffer); - } - - TCompactTrie<TChar, ui32> trie(buffer.Buffer().Data(), buffer.Buffer().Size()); - ui32 value = 0; + builder.Add(TConvertKey<TChar>::Convert(data[i]), i + 1); + } + builder.Save(buffer); + } + + TCompactTrie<TChar, ui32> trie(buffer.Buffer().Data(), buffer.Buffer().Size()); + ui32 value = 0; auto iter(MakeSearchIterator(trie)); MoveIter(iter, TConvertKey<TChar>::Convert(TStringBuf("abc"))); - UNIT_ASSERT(!iter.GetValue(&value)); - + UNIT_ASSERT(!iter.GetValue(&value)); + iter = MakeSearchIterator(trie); MoveIter(iter, TConvertKey<TChar>::Convert(TStringBuf("abbbc"))); - UNIT_ASSERT(iter.GetValue(&value)); - UNIT_ASSERT_EQUAL(value, 3); - + UNIT_ASSERT(iter.GetValue(&value)); + UNIT_ASSERT_EQUAL(value, 3); + iter = MakeSearchIterator(trie); UNIT_ASSERT(iter.Advance(TConvertKey<TChar>::Convert(TStringBuf("bdfa")))); - UNIT_ASSERT(!iter.GetValue(&value)); - + UNIT_ASSERT(!iter.GetValue(&value)); + iter = MakeSearchIterator(trie); UNIT_ASSERT(iter.Advance(TConvertKey<TChar>::Convert(TStringBuf("bdfaa")))); - UNIT_ASSERT(iter.GetValue(&value)); - UNIT_ASSERT_EQUAL(value, 4); - + UNIT_ASSERT(iter.GetValue(&value)); + UNIT_ASSERT_EQUAL(value, 4); + UNIT_ASSERT(!MakeSearchIterator(trie).Advance(TChar('z'))); UNIT_ASSERT(!MakeSearchIterator(trie).Advance(TConvertKey<TChar>::Convert(TStringBuf("cdf")))); UNIT_ASSERT(!MakeSearchIterator(trie).Advance(TConvertKey<TChar>::Convert(TStringBuf("abca")))); -} - -void TCompactTrieTest::TestSearchIterChar() { - TestSearchIterImpl<char>(); -} - -void TCompactTrieTest::TestSearchIterWchar() { - TestSearchIterImpl<wchar16>(); -} +} + +void TCompactTrieTest::TestSearchIterChar() { + TestSearchIterImpl<char>(); +} + +void TCompactTrieTest::TestSearchIterWchar() { + TestSearchIterImpl<wchar16>(); +} void TCompactTrieTest::TestSearchIterWchar32() { TestSearchIterImpl<wchar32>(); |