aboutsummaryrefslogtreecommitdiffstats
path: root/util/digest/fnv_ut.cpp
blob: 3c1588bbad3f63b8f46329e783a0d7feaf041c66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "fnv.h"

#include <library/cpp/testing/unittest/registar.h>

Y_UNIT_TEST_SUITE(TFnvTest) {
    Y_UNIT_TEST(TestFnv32) {
        const auto h32 = ULL(2849763999);
        UNIT_ASSERT_EQUAL(FnvHash<ui32>("1234567", 7), h32);
        UNIT_ASSERT_EQUAL(FnvHash<ui32>(TStringBuf("1234567")), h32);

        UNIT_ASSERT_EQUAL(FnvHash<ui32>(nullptr, 0), FNV32INIT);
        UNIT_ASSERT_EQUAL(FnvHash<ui32>(TStringBuf()), FNV32INIT);
    }

    Y_UNIT_TEST(TestFnv64) {
        const auto h64 = ULL(2449551094593701855);
        UNIT_ASSERT_EQUAL(FnvHash<ui64>("1234567", 7), h64);
        UNIT_ASSERT_EQUAL(FnvHash<ui64>(TStringBuf("1234567")), h64);

        UNIT_ASSERT_EQUAL(FnvHash<ui64>(nullptr, 0), FNV64INIT);
        UNIT_ASSERT_EQUAL(FnvHash<ui64>(TStringBuf()), FNV64INIT);
    }
} // Y_UNIT_TEST_SUITE(TFnvTest)