diff options
author | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/digest/sequence_ut.cpp |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/digest/sequence_ut.cpp')
-rw-r--r-- | util/digest/sequence_ut.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/util/digest/sequence_ut.cpp b/util/digest/sequence_ut.cpp new file mode 100644 index 00000000000..87d6102ee59 --- /dev/null +++ b/util/digest/sequence_ut.cpp @@ -0,0 +1,62 @@ +#include "sequence.h" + +#include <library/cpp/testing/unittest/registar.h> +#include <util/generic/map.h> +#include <util/generic/vector.h> + +class TRangeHashTest: public TTestBase { + UNIT_TEST_SUITE(TRangeHashTest); + UNIT_TEST(TestStrokaInt) + UNIT_TEST(TestIntVector) + UNIT_TEST(TestOneElement) + UNIT_TEST(TestMap); + UNIT_TEST(TestCollectionIndependancy); + UNIT_TEST_SUITE_END(); + +private: + inline void TestStrokaInt() { + const size_t canonicalHash = static_cast<size_t>(ULL(12727184940294366172)); + UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(TString("12345"))); + } + + inline void TestIntVector() { + const size_t canonicalHash = static_cast<size_t>(ULL(1351128487744230578)); + TVector<int> testVec = {1, 2, 4, 3}; + UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(testVec)); + } + + inline void TestOneElement() { + const int testVal = 42; + TVector<int> testVec = {testVal}; + UNIT_ASSERT_UNEQUAL(THash<int>()(testVal), TRangeHash<>()(testVec)); + } + + inline void TestMap() { + const size_t canonicalHash = static_cast<size_t>(ULL(4415387926488545605)); + TMap<TString, int> testMap{{"foo", 123}, {"bar", 456}}; + UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(testMap)); + } + + inline void TestCollectionIndependancy() { + TVector<char> testVec = {'a', 'b', 'c'}; + TString testStroka = "abc"; + UNIT_ASSERT_EQUAL(TRangeHash<>()(testVec), TRangeHash<>()(testStroka)); + } +}; + +class TSequenceHashTest: public TTestBase { + UNIT_TEST_SUITE(TSequenceHashTest); + UNIT_TEST(TestSimpleBuffer) + UNIT_TEST_SUITE_END(); + +private: + inline void TestSimpleBuffer() { + int arr[] = {1, 2, 3}; + const size_t canonicalHash = static_cast<size_t>(ULL(3903918011533391876)); + TContiguousHash<TSimpleRangeHash> hasher; + UNIT_ASSERT_EQUAL(canonicalHash, hasher(TArrayRef<int>(arr, arr + 3))); + } +}; + +UNIT_TEST_SUITE_REGISTRATION(TRangeHashTest); +UNIT_TEST_SUITE_REGISTRATION(TSequenceHashTest); |