add murmur3 partitioner
[libdht.git] / test_murmur3.c
blob83a1ff1da5a47b9d3128fea0e45c5570f0cbdc8c
1 #include <stdio.h>
2 #include <string.h>
4 #include "murmur3.h"
6 int
7 main(int argc, char **argv)
9 uint64_t hash[2];
10 char *testcase0 = "";
11 char *testcase1 = "a";
12 char *testcase2 = "$!";
13 char *testcase3 = "hello world!";
14 char *testcase4 = "abracadabra";
15 char *testcase5 = "Abracadabra";
16 char *testcase6 = "Lorem ipsum dolor sit amet.";
17 char *testcase7 = "Lorem ipsum dolor sit amet orci aliquam.";
18 char *testcase8 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eu augue quis velit massa nunc.";
19 char *testcase9 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ultricies quam sit amet odio finibus ultricies. Integer vitae ante libero. Etiam gravida ac purus nec efficitur. Nam faucibus finibus velit, eu pulvinar nibh condimentum sed. Quisque tempor sed.";
21 murmurhash3_x64_128(testcase0, strlen(testcase0), 0, hash);
22 if ((hash[0] != 0x0LLU) || (hash[1] != 0x0LLU))
23 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase0, hash[0], hash[1], 0x0LLU, 0x0LLU);
24 else
25 printf("PASSED\n");
27 murmurhash3_x64_128(testcase1, strlen(testcase1), 0, hash);
28 if ((hash[0] != 0x85555565f6597889LLU) || (hash[1] != 0xe6b53a48510e895aLLU))
29 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase1, hash[0], hash[1], 0x85555565f6597889LLU, 0xe6b53a48510e895aLLU);
30 else
31 printf("PASSED\n");
33 murmurhash3_x64_128(testcase2, strlen(testcase2), 0, hash);
34 if ((hash[0] != 0xbd5f7bc8a4fdd541LLU) || (hash[1] != 0x2638a8ef74dade00LLU))
35 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase2, hash[0], hash[1], 0xbd5f7bc8a4fdd541LLU, 0x2638a8ef74dade00LLU);
36 else
37 printf("PASSED\n");
39 murmurhash3_x64_128(testcase3, strlen(testcase3), 0, hash);
40 if ((hash[0] != 0x5aa80377fe21bbe3LLU) || (hash[1] != 0xedf56b1420cea7e7LLU))
41 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase3, hash[0], hash[1], 0x5aa80377fe21bbe3LLU, 0xedf56b1420cea7e7LLU);
42 else
43 printf("PASSED\n");
45 murmurhash3_x64_128(testcase4, strlen(testcase4), 0, hash);
46 if ((hash[0] != 0x3386097a32a76032LLU) || (hash[1] != 0x216f524eb811e738LLU))
47 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase4, hash[0], hash[1], 0x3386097a32a76032LLU, 0x216f524eb811e738LLU);
48 else
49 printf("PASSED\n");
51 murmurhash3_x64_128(testcase5, strlen(testcase5), 0, hash);
52 if ((hash[0] != 0x84c607dbc50d6e93LLU) || (hash[1] != 0x68532ed845d04979LLU))
53 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase5, hash[0], hash[1], 0x84c607dbc50d6e93LLU, 0x68532ed845d04979LLU);
54 else
55 printf("PASSED\n");
57 murmurhash3_x64_128(testcase6, strlen(testcase6), 0, hash);
58 if ((hash[0] != 0x147b136c7bcdcd01LLU) || (hash[1] != 0x697f1d69b4d42a70LLU))
59 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase6, hash[0], hash[1], 0x147b136c7bcdcd01LLU, 0x697f1d69b4d42a70LLU);
60 else
61 printf("PASSED\n");
63 murmurhash3_x64_128(testcase7, strlen(testcase7), 0, hash);
64 if ((hash[0] != 0x3e19e6296c644dfbLLU) || (hash[1] != 0x91157457fc87a37bLLU))
65 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase7, hash[0], hash[1], 0x3e19e6296c644dfbLLU, 0x91157457fc87a37bLLU);
66 else
67 printf("PASSED\n");
69 murmurhash3_x64_128(testcase8, strlen(testcase8), 0, hash);
70 if ((hash[0] != 0xa1148cf5710c8478LLU) || (hash[1] != 0x1eccb6487c585ed0LLU))
71 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase8, hash[0], hash[1], 0xa1148cf5710c8478LLU, 0x1eccb6487c585ed0LLU);
72 else
73 printf("PASSED\n");
75 murmurhash3_x64_128(testcase9, strlen(testcase9), 0, hash);
76 if ((hash[0] != 0xe3787b529415e368LLU) || (hash[1] != 0xbab4b8be10f4213fLLU))
77 printf("FAILED \"%s\": %llx%llx should be %llx%llx\n", testcase9, hash[0], hash[1], 0xe3787b529415e368LLU, 0xbab4b8be10f4213fLLU);
78 else
79 printf("PASSED\n");
81 return 0;