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