Skip to content

Commit 4eecdca

Browse files
committed
Add MurmurHash3() unit test
Useful as a source of test vectors to anyone re-implementing bloom filters.
1 parent af6a02a commit 4eecdca

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/test/hash_tests.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <boost/test/unit_test.hpp>
2+
#include <vector>
3+
4+
#include "util.h"
5+
#include "hash.h"
6+
7+
using namespace std;
8+
9+
BOOST_AUTO_TEST_SUITE(hash_tests)
10+
11+
BOOST_AUTO_TEST_CASE(murmurhash3)
12+
{
13+
14+
#define T(expected, seed, data) BOOST_CHECK_EQUAL(MurmurHash3(seed, ParseHex(data)), expected)
15+
16+
// Test MurmurHash3 with various inputs. Of course this is retested in the
17+
// bloom filter tests - they would fail if MurmurHash3() had any problems -
18+
// but is useful for those trying to implement Bitcoin libraries as a
19+
// source of test data for their MurmurHash3() primitive during
20+
// development.
21+
//
22+
// The magic number 0xFBA4C795 comes from CBloomFilter::Hash()
23+
24+
T(0x00000000, 0x00000000, "");
25+
T(0x6a396f08, 0xFBA4C795, "");
26+
T(0x81f16f39, 0xffffffff, "");
27+
28+
T(0x514e28b7, 0x00000000, "00");
29+
T(0xea3f0b17, 0xFBA4C795, "00");
30+
T(0xfd6cf10d, 0x00000000, "ff");
31+
32+
T(0x16c6b7ab, 0x00000000, "0011");
33+
T(0x8eb51c3d, 0x00000000, "001122");
34+
T(0xb4471bf8, 0x00000000, "00112233");
35+
T(0xe2301fa8, 0x00000000, "0011223344");
36+
T(0xfc2e4a15, 0x00000000, "001122334455");
37+
T(0xb074502c, 0x00000000, "00112233445566");
38+
T(0x8034d2a0, 0x00000000, "0011223344556677");
39+
T(0xb4698def, 0x00000000, "001122334455667788");
40+
41+
#undef T
42+
}
43+
44+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)