Blender V4.3
BLI_hash_mm2a_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include "BLI_hash_mm2a.hh"
8
9/* NOTE: Reference results are taken from reference implementation
10 * (cpp code, CMurmurHash2A variant):
11 * https://smhasher.googlecode.com/svn-history/r130/trunk/MurmurHash2.cpp
12 */
13
14TEST(hash_mm2a, MM2ABasic)
15{
17
18 const char *data = "Blender";
19
20 BLI_hash_mm2a_init(&mm2, 0);
21 BLI_hash_mm2a_add(&mm2, (const uchar *)data, strlen(data));
22#ifdef __LITTLE_ENDIAN__
23 EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 1633988145);
24#else
25 EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 959283772);
26#endif
27}
28
29TEST(hash_mm2a, MM2AConcatenateStrings)
30{
33
34 const char *data1 = "Blender";
35 const char *data2 = " is ";
36 const char *data3 = "FaNtAsTiC";
37 const char *data123 = "Blender is FaNtAsTiC";
38
39 BLI_hash_mm2a_init(&mm2, 0);
40 BLI_hash_mm2a_add(&mm2, (const uchar *)data1, strlen(data1));
41 BLI_hash_mm2a_add(&mm2, (const uchar *)data2, strlen(data2));
42 BLI_hash_mm2a_add(&mm2, (const uchar *)data3, strlen(data3));
43 hash = BLI_hash_mm2a_end(&mm2);
44 BLI_hash_mm2a_init(&mm2, 0);
45 BLI_hash_mm2a_add(&mm2, (const uchar *)data123, strlen(data123));
46#ifdef __LITTLE_ENDIAN__
47 EXPECT_EQ(hash, 1545105348);
48#else
49 EXPECT_EQ(hash, 2604964730);
50#endif
52}
53
54TEST(hash_mm2a, MM2AIntegers)
55{
58
59 const int ints[4] = {1, 2, 3, 4};
60
61 BLI_hash_mm2a_init(&mm2, 0);
62 BLI_hash_mm2a_add_int(&mm2, ints[0]);
63 BLI_hash_mm2a_add_int(&mm2, ints[1]);
64 BLI_hash_mm2a_add_int(&mm2, ints[2]);
65 BLI_hash_mm2a_add_int(&mm2, ints[3]);
66 hash = BLI_hash_mm2a_end(&mm2);
67 BLI_hash_mm2a_init(&mm2, 0);
68 BLI_hash_mm2a_add(&mm2, (const uchar *)ints, sizeof(ints));
69 /* Yes, same hash here on little and big endian. */
70#ifdef __LITTLE_ENDIAN__
71 EXPECT_EQ(hash, 405493096);
72#else
73 EXPECT_EQ(hash, 405493096);
74#endif
76}
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void BLI_hash_mm2a_init(BLI_HashMurmur2A *mm2, uint32_t seed)
Definition hash_mm2a.cc:62
void BLI_hash_mm2a_add(BLI_HashMurmur2A *mm2, const unsigned char *data, size_t len)
Definition hash_mm2a.cc:70
void BLI_hash_mm2a_add_int(BLI_HashMurmur2A *mm2, int data)
Definition hash_mm2a.cc:85
uint32_t BLI_hash_mm2a_end(BLI_HashMurmur2A *mm2)
Definition hash_mm2a.cc:90
TEST(hash_mm2a, MM2ABasic)
unsigned char uchar
#define hash
Definition noise.c:154
unsigned int uint32_t
Definition stdint.h:80