Line data Source code
1 : /* Tests */
2 :
3 : // murmur3
4 : //
5 : #include <murmur3/murmur3.h>
6 :
7 :
8 : // self
9 : //
10 : #include "catch_main.h"
11 :
12 :
13 : // C
14 : //
15 : //#include <stdio.h>
16 : //#include <stdlib.h>
17 : //#include <stdint.h>
18 : //#include <string.h>
19 :
20 :
21 : // last include
22 : //
23 : #include <snapdev/poison.h>
24 :
25 :
26 :
27 :
28 3 : CATCH_TEST_CASE("basic", "[version][valid]")
29 : {
30 2 : CATCH_START_SECTION("Verify C version")
31 : {
32 : //#define TESTHASH(arch, nbytes, seed, str, expected) { \
33 : // char *input = str; \
34 : // uint32_t hash[4]; \
35 : // char buf[33]; \
36 : // MurmurHash3_##arch##_##nbytes(input, strlen(input), (seed), hash); \
37 : // hex##nbytes(hash, buf); \
38 : // if (strcmp(buf, expected) != 0) { \
39 : // printf("FAIL(line %i): %s != %s\n", __LINE__, expected, buf); \
40 : // failed++; \
41 : // } else passed++; \
42 : // }
43 :
44 1 : std::uint32_t hash[4];
45 :
46 : //TESTHASH(x86, 32, 1234, "Hello, world!", "faf6cdb3");
47 2 : std::string const hello_world("Hello, world!");
48 1 : MurmurHash3_x86_32(hello_world.c_str(), hello_world.length(), 1234, hash);
49 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex32(hash) == "faf6cdb3");
50 :
51 : //TESTHASH(x86, 32, 4321, "Hello, world!", "bf505788");
52 1 : MurmurHash3_x86_32(hello_world.c_str(), hello_world.length(), 4321, hash);
53 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex32(hash) == "bf505788");
54 :
55 : //TESTHASH(x86, 32, 1234, "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "8905ac28");
56 2 : std::string const x28("xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
57 1 : MurmurHash3_x86_32(x28.c_str(), x28.length(), 1234, hash);
58 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex32(hash) == "8905ac28");
59 :
60 : //TESTHASH(x86, 32, 1234, "", "0f2cc00b");
61 2 : std::string const empty("");
62 1 : MurmurHash3_x86_32(empty.c_str(), empty.length(), 1234, hash);
63 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex32(hash) == "0f2cc00b");
64 :
65 : //TESTHASH(x86, 128, 123, "Hello, world!", "61c9129e5a1aacd7a41621629e37c886");
66 1 : MurmurHash3_x86_128(hello_world.c_str(), hello_world.length(), 123, hash);
67 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "61c9129e5a1aacd7a41621629e37c886");
68 :
69 : //TESTHASH(x86, 128, 321, "Hello, world!", "d5fbdcb3c26c4193045880c5a7170f0f");
70 1 : MurmurHash3_x86_128(hello_world.c_str(), hello_world.length(), 321, hash);
71 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "d5fbdcb3c26c4193045880c5a7170f0f");
72 :
73 : //TESTHASH(x86, 128, 123, "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "5e40bab278825a164cf929d31fec6047");
74 1 : MurmurHash3_x86_128(x28.c_str(), x28.length(), 123, hash);
75 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "5e40bab278825a164cf929d31fec6047");
76 :
77 : //TESTHASH(x86, 128, 123, "", "fedc524526f3e79926f3e79926f3e799");
78 1 : MurmurHash3_x86_128(empty.c_str(), empty.length(), 123, hash);
79 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "fedc524526f3e79926f3e79926f3e799");
80 :
81 : //TESTHASH(x64, 128, 123, "Hello, world!", "8743acad421c8c73d373c3f5f19732fd");
82 1 : MurmurHash3_x64_128(hello_world.c_str(), hello_world.length(), 123, hash);
83 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "8743acad421c8c73d373c3f5f19732fd");
84 :
85 : //TESTHASH(x64, 128, 321, "Hello, world!", "f86d4004ca47f42bb9546c7979200aee");
86 1 : MurmurHash3_x64_128(hello_world.c_str(), hello_world.length(), 321, hash);
87 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "f86d4004ca47f42bb9546c7979200aee");
88 :
89 : //TESTHASH(x64, 128, 123, "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "becf7e04dbcf74637751664ef66e73e0");
90 1 : MurmurHash3_x64_128(x28.c_str(), x28.length(), 123, hash);
91 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "becf7e04dbcf74637751664ef66e73e0");
92 :
93 : //TESTHASH(x64, 128, 123, "", "4cd9597081679d1abd92f8784bace33d");
94 1 : MurmurHash3_x64_128(empty.c_str(), empty.length(), 123, hash);
95 1 : CATCH_CHECK(SNAP_CATCH2_NAMESPACE::hex128(hash) == "4cd9597081679d1abd92f8784bace33d");
96 : }
97 : CATCH_END_SECTION()
98 7 : }
99 :
100 :
101 : // vim: ts=4 sw=4 et
|