45 m_value += x * (((uint64_t)0xc151429 << 32) | 0x517851bf);
46 m_value ^= (((uint64_t)0x9183bfec << 32) | 0x01921947);
52 size_t n = str.length();
55 for (
size_t i=0; i<n; ++i)
62 return m_value == other.m_value;
68 return m_value != other.m_value;
77 static void Test_Checksum_DefaultValue()
82 checksum.
Value() == 0);
85 static void Test_Checksum_Add()
90 uint64_t v1 = checksum.
Value();
93 uint64_t v2 = checksum.
Value();
100 static void Test_Checksum_SameChecksum()
105 checksumA.
Add(
"testing");
106 checksumB.
Add(
"testing");
112 static void Test_Checksum_OrderIsSignificant_Numeric()
119 uint64_t valueA = checksumA.
Value();
123 uint64_t valueB = checksumB.
Value();
128 static void Test_Checksum_OrderIsSignificant_String()
133 checksumA.
Add(
"123");
134 checksumA.
Add(
"234");
135 uint64_t valueA = checksumA.
Value();
137 checksumB.
Add(
"234");
138 checksumB.
Add(
"123");
139 uint64_t valueB = checksumB.
Value();
144 static void Test_Checksum_OrderIsSignificant_String_1()
149 checksumA.
Add(
"abcdef");
150 uint64_t valueA = checksumA.
Value();
152 checksumB.
Add(
"abdcef");
153 uint64_t valueB = checksumB.
Value();
158 static void Test_Checksum_OrderIsSignificant_String_2()
163 checksumA.
Add(
"hello ");
164 checksumA.
Add(
"world");
165 uint64_t valueA = checksumA.
Value();
167 checksumB.
Add(
"hello");
168 checksumB.
Add(
" world");
169 uint64_t valueB = checksumB.
Value();
174 static void Test_Checksum_OrderIsSignificant_String_3()
179 checksumA.
Add(
"string x \"modified\"\n");
180 checksumA.
Add(
"string y \"value 2\"\n");
181 checksumA.
Add(
"string x \"value\\nhello\"\n");
182 uint64_t valueA = checksumA.
Value();
184 checksumB.
Add(
"string x \"value 1\"\n");
185 checksumB.
Add(
"string y \"value 2\"\n");
186 checksumB.
Add(
"string x \"value\\nhello\"\n");
187 uint64_t valueB = checksumB.
Value();
192 static void Test_Checksum_String_Concatenation()
197 checksumA.
Add(
"hello");
198 checksumA.
Add(
" world");
199 uint64_t valueA = checksumA.
Value();
201 checksumB.
Add(
"hello world");
202 uint64_t valueB = checksumB.
Value();
209 UNITTEST(Test_Checksum_DefaultValue);
211 UNITTEST(Test_Checksum_SameChecksum);
212 UNITTEST(Test_Checksum_OrderIsSignificant_Numeric);
213 UNITTEST(Test_Checksum_OrderIsSignificant_String);
214 UNITTEST(Test_Checksum_OrderIsSignificant_String_1);
215 UNITTEST(Test_Checksum_OrderIsSignificant_String_2);
216 UNITTEST(Test_Checksum_OrderIsSignificant_String_3);
217 UNITTEST(Test_Checksum_String_Concatenation);
uint64_t Value() const
Retrieves the value of the checksum, as a uint64_t.
void Add(uint64_t x)
Add a uint64_t to the checksum.
#define UNITTESTS(class)
Helper for unit test case execution.
bool operator!=(const Checksum &other) const
Compares one Checksum to another for inequality.
bool operator==(const Checksum &other) const
Compares one Checksum to another for equality.
Checksum()
Constructs a zeroed checksum.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
#define UNITTEST(functionname)
Helper for unit test case execution.