aboutsummaryrefslogtreecommitdiffstats
path: root/util/digest/murmur_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 /util/digest/murmur_ut.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/digest/murmur_ut.cpp')
-rw-r--r--util/digest/murmur_ut.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/util/digest/murmur_ut.cpp b/util/digest/murmur_ut.cpp
new file mode 100644
index 0000000000..29287668bc
--- /dev/null
+++ b/util/digest/murmur_ut.cpp
@@ -0,0 +1,85 @@
+
+#include "murmur.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+class TMurmurHashTest: public TTestBase {
+ UNIT_TEST_SUITE(TMurmurHashTest);
+ UNIT_TEST(TestHash32)
+ UNIT_TEST(TestUnalignedHash32)
+ UNIT_TEST(TestHash64)
+ UNIT_TEST(TestUnalignedHash64)
+ UNIT_TEST(TestWrapperBiggerTypes)
+ UNIT_TEST_SUITE_END();
+
+private:
+ inline void TestHash32() {
+ ui8 buf[256];
+
+ for (size_t i = 0; i < 256; ++i) {
+ buf[i] = i;
+ }
+
+ Test<ui32>(buf, 256, 2373126550UL);
+ TestWrapper<ui8, ui32>({buf, buf + 256}, 2373126550UL);
+ Test<ui32>(buf, 255, 3301607533UL);
+ Test<ui32>(buf, 254, 2547410121UL);
+ Test<ui32>(buf, 253, 80030810UL);
+ }
+
+ inline void TestUnalignedHash32() {
+ ui8 buf[257];
+ ui8* unalignedBuf = buf + 1;
+
+ for (size_t i = 0; i < 256; ++i) {
+ unalignedBuf[i] = i;
+ }
+
+ Test<ui32>(unalignedBuf, 256, 2373126550UL);
+ }
+
+ inline void TestHash64() {
+ ui8 buf[256];
+
+ for (size_t i = 0; i < 256; ++i) {
+ buf[i] = i;
+ }
+
+ Test<ui64>(buf, 256, ULL(12604435678857905857));
+ TestWrapper<ui8, ui64>({buf, buf + 256}, ULL(12604435678857905857));
+ Test<ui64>(buf, 255, ULL(1708835094528446095));
+ Test<ui64>(buf, 254, ULL(5077937678736514994));
+ Test<ui64>(buf, 253, ULL(11553864555081396353));
+ }
+
+ inline void TestUnalignedHash64() {
+ ui8 buf[257];
+ ui8* unalignedBuf = buf + 1;
+
+ for (size_t i = 0; i < 256; ++i) {
+ unalignedBuf[i] = i;
+ }
+
+ Test<ui64>(unalignedBuf, 256, ULL(12604435678857905857));
+ }
+
+ inline void TestWrapperBiggerTypes() {
+ ui32 buf[] = {24, 42};
+ TestWrapper<ui32, ui32>({buf, buf + 2}, MurmurHash<ui32>(buf, sizeof(ui32) * 2));
+ TestWrapper<ui32, ui64>({buf, buf + 2}, MurmurHash<ui64>(buf, sizeof(ui32) * 2));
+ }
+
+private:
+ template <class T>
+ inline void Test(const void* data, size_t len, T expected) {
+ UNIT_ASSERT_STRINGS_EQUAL(ToString(MurmurHash<T>(data, len)), ToString(expected));
+ }
+
+ template <class E, class T>
+ inline void TestWrapper(const TArrayRef<E>& array, T expected) {
+ auto val = TMurmurHash<T>()(array);
+ UNIT_ASSERT_EQUAL(val, expected);
+ }
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TMurmurHashTest);