aboutsummaryrefslogtreecommitdiffstats
path: root/util/digest/sequence_ut.cpp
blob: 87d6102ee598b6a180ac5d6817e34bf06f9e7943 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);