aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/digest/sfh/sfh_ut.cpp
blob: 79606232de34de8ceb5c39c15c3bbbdd8644db7b (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
#include "sfh.h" 
 
#include <library/cpp/testing/unittest/registar.h>
 
#include <util/stream/output.h>
 
class TSfhTest: public TTestBase { 
    UNIT_TEST_SUITE(TSfhTest); 
    UNIT_TEST(TestSfh) 
    UNIT_TEST_SUITE_END(); 
 
private: 
    inline void TestSfh() { 
        ui8 buf[256]; 
 
        for (size_t i = 0; i < 256; ++i) { 
            buf[i] = i; 
        } 
 
        Test(buf, 256, 3840866583UL); 
        Test(buf, 255, 325350515UL); 
        Test(buf, 254, 2920741773UL); 
        Test(buf, 253, 3586628615UL); 
    } 
 
private: 
    inline void Test(const void* data, size_t len, ui32 expected) { 
        const ui32 res = SuperFastHash(data, len); 
 
        try { 
            UNIT_ASSERT_EQUAL(res, expected); 
        } catch (...) { 
            Cerr << res << ", " << expected << Endl; 
 
            throw; 
        } 
    } 
}; 
 
UNIT_TEST_SUITE_REGISTRATION(TSfhTest);