aboutsummaryrefslogtreecommitdiffstats
path: root/util/digest/multi_ut.cpp
blob: dff64ff0cc18e05f01a2c6aeaf82a898a7c869de (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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "multi.h"

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

#include <util/stream/output.h>

class TMultiHashTest: public TTestBase {
    UNIT_TEST_SUITE(TMultiHashTest);
    UNIT_TEST(TestStrInt)
    UNIT_TEST(TestIntStr)
    UNIT_TEST(TestSimpleCollision)
    UNIT_TEST(TestTypes)
    UNIT_TEST_SUITE_END();

private:
    inline void TestStrInt() {
        UNIT_ASSERT_EQUAL(MultiHash(TString("1234567"), static_cast<int>(123)), static_cast<size_t>(ULL(17038203285960021630)));
    }

    inline void TestIntStr() {
        UNIT_ASSERT_EQUAL(MultiHash(static_cast<int>(123), TString("1234567")), static_cast<size_t>(ULL(9973288649881090712)));
    }

    inline void TestSimpleCollision() {
        UNIT_ASSERT_UNEQUAL(MultiHash(1, 1, 0), MultiHash(2, 2, 0));
    }

    inline void TestTypes() {
        UNIT_ASSERT_EQUAL(MultiHash("aaa", (ui64)123), MultiHash("aaa", 123));
        UNIT_ASSERT_EQUAL(MultiHash("aaa", (i64)123), MultiHash("aaa", 123));
        UNIT_ASSERT_EQUAL(MultiHash("aaa", (i32)123), MultiHash("aaa", 123));
        UNIT_ASSERT_EQUAL(MultiHash("aaa", (ui32)123), MultiHash("aaa", 123));
        UNIT_ASSERT_EQUAL(MultiHash("aaa", (i64)-123), MultiHash("aaa", -123));
        UNIT_ASSERT_EQUAL(MultiHash("aaa", (i32)-123), MultiHash("aaa", -123));
    }
};

UNIT_TEST_SUITE_REGISTRATION(TMultiHashTest);