Blender V5.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 * (C++ code, CMurmurHash2A variant):
11 * https://smhasher.googlecode.com/svn-history/r130/trunk/MurmurHash2.cpp
12 */
13
14namespace blender {
15
16TEST(hash_mm2a, MM2ABasic)
17{
19
20 const char *data = "Blender";
21
22 BLI_hash_mm2a_init(&mm2, 0);
23 BLI_hash_mm2a_add(&mm2, reinterpret_cast<const uchar *>(data), strlen(data));
24 /* NOTE: this is endianness-sensitive. */
25 /* On BE systems, the expected value would be 959283772. */
26 EXPECT_EQ(BLI_hash_mm2a_end(&mm2), 1633988145);
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, reinterpret_cast<const uchar *>(data1), strlen(data1));
41 BLI_hash_mm2a_add(&mm2, reinterpret_cast<const uchar *>(data2), strlen(data2));
42 BLI_hash_mm2a_add(&mm2, reinterpret_cast<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, reinterpret_cast<const uchar *>(data123), strlen(data123));
46 /* NOTE: this is endianness-sensitive. */
47 /* On BE systems, the expected value would be 2604964730. */
48 EXPECT_EQ(hash, 1545105348);
50}
51
52TEST(hash_mm2a, MM2AIntegers)
53{
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, reinterpret_cast<const uchar *>(ints), sizeof(ints));
67 /* NOTE: this is endianness-sensitive. */
68 /* Actually, same hash here on little and big endian. */
69 EXPECT_EQ(hash, 405493096);
71}
72
73} // namespace blender
BMesh Iterators.
uint32_t BLI_hash_mm2a_end(BLI_HashMurmur2A *mm2)
Definition hash_mm2a.cc:92
void BLI_hash_mm2a_add(BLI_HashMurmur2A *mm2, const unsigned char *data, size_t len)
Definition hash_mm2a.cc:72
TEST(array_store, Nop)
unsigned int uint32_t
Definition BKE_text.h:81
unsigned char uchar
Definition BKE_text.h:58
BMesh const char void * data
void BLI_hash_mm2a_add_int(BLI_HashMurmur2A *mm2, int data)
Definition hash_mm2a.cc:87
void BLI_hash_mm2a_init(BLI_HashMurmur2A *mm2, uint32_t seed)
Definition hash_mm2a.cc:64
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
#define hash
Definition noise_c.cc:156