Blender V5.0
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 * (C++ 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 /* NOTE: this is endianness-sensitive. */
23 /* On BE systems, the expected value would be 959283772. */
24 EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 1633988145);
25}
26
27TEST(hash_mm2a, MM2AConcatenateStrings)
28{
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 uchar *)data1, strlen(data1));
39 BLI_hash_mm2a_add(&mm2, (const uchar *)data2, strlen(data2));
40 BLI_hash_mm2a_add(&mm2, (const uchar *)data3, strlen(data3));
41 hash = BLI_hash_mm2a_end(&mm2);
42 BLI_hash_mm2a_init(&mm2, 0);
43 BLI_hash_mm2a_add(&mm2, (const uchar *)data123, strlen(data123));
44 /* NOTE: this is endianness-sensitive. */
45 /* On BE systems, the expected value would be 2604964730. */
46 EXPECT_EQ(hash, 1545105348);
48}
49
50TEST(hash_mm2a, MM2AIntegers)
51{
53 uint32_t hash;
54
55 const int ints[4] = {1, 2, 3, 4};
56
57 BLI_hash_mm2a_init(&mm2, 0);
58 BLI_hash_mm2a_add_int(&mm2, ints[0]);
59 BLI_hash_mm2a_add_int(&mm2, ints[1]);
60 BLI_hash_mm2a_add_int(&mm2, ints[2]);
61 BLI_hash_mm2a_add_int(&mm2, ints[3]);
62 hash = BLI_hash_mm2a_end(&mm2);
63 BLI_hash_mm2a_init(&mm2, 0);
64 BLI_hash_mm2a_add(&mm2, (const uchar *)ints, sizeof(ints));
65 /* NOTE: this is endianness-sensitive. */
66 /* Actually, same hash here on little and big endian. */
67 EXPECT_EQ(hash, 405493096);
69}
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
BMesh const char void * data
#define hash
Definition noise_c.cc:154