This commit is contained in:
@ -14,7 +14,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <IACore/DataOps.hpp>
|
||||
|
||||
#include <IACore/IATest.hpp>
|
||||
|
||||
using namespace IACore;
|
||||
@ -25,89 +24,92 @@ using namespace IACore;
|
||||
|
||||
IAT_BEGIN_BLOCK(Core, DataOps)
|
||||
|
||||
bool TestCRC32() {
|
||||
auto test_crc32() -> bool {
|
||||
{
|
||||
String s = "123456789";
|
||||
Span<const u8> span(reinterpret_cast<const u8 *>(s.data()), s.size());
|
||||
u32 result = DataOps::CRC32(span);
|
||||
const String s = "123456789";
|
||||
const Span<const u8> span(reinterpret_cast<const u8 *>(s.data()), s.size());
|
||||
const u32 result = DataOps::crc32(span);
|
||||
|
||||
IAT_CHECK_EQ(result, 0xE3069283);
|
||||
}
|
||||
|
||||
{
|
||||
u32 result = DataOps::CRC32({});
|
||||
const u32 result = DataOps::crc32({});
|
||||
IAT_CHECK_EQ(result, 0U);
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<u8> buffer(33);
|
||||
for (size_t i = 1; i < 33; ++i)
|
||||
buffer[i] = (u8)i;
|
||||
Vec<u8> buffer(33);
|
||||
for (usize i = 1; i < 33; ++i) {
|
||||
buffer[i] = static_cast<u8>(i);
|
||||
}
|
||||
|
||||
std::vector<u8> refData(32);
|
||||
for (size_t i = 0; i < 32; ++i)
|
||||
refData[i] = (u8)(i + 1);
|
||||
Vec<u8> ref_data(32);
|
||||
for (usize i = 0; i < 32; ++i) {
|
||||
ref_data[i] = static_cast<u8>(i + 1);
|
||||
}
|
||||
|
||||
u32 hashRef =
|
||||
DataOps::CRC32(Span<const u8>(refData.data(), refData.size()));
|
||||
const u32 hash_ref =
|
||||
DataOps::crc32(Span<const u8>(ref_data.data(), ref_data.size()));
|
||||
|
||||
u32 hashUnaligned = DataOps::CRC32(Span<const u8>(buffer.data() + 1, 32));
|
||||
const u32 hash_unaligned =
|
||||
DataOps::crc32(Span<const u8>(buffer.data() + 1, 32));
|
||||
|
||||
IAT_CHECK_EQ(hashRef, hashUnaligned);
|
||||
IAT_CHECK_EQ(hash_ref, hash_unaligned);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestHash_xxHash() {
|
||||
auto test_hash_xxhash() -> bool {
|
||||
{
|
||||
String s = "123456789";
|
||||
u32 result = DataOps::Hash_xxHash(s);
|
||||
const String s = "123456789";
|
||||
const u32 result = DataOps::hash_xxhash(s);
|
||||
IAT_CHECK_EQ(result, 0x937bad67);
|
||||
}
|
||||
|
||||
{
|
||||
String s = "The quick brown fox jumps over the lazy dog";
|
||||
u32 result = DataOps::Hash_xxHash(s);
|
||||
const String s = "The quick brown fox jumps over the lazy dog";
|
||||
const u32 result = DataOps::hash_xxhash(s);
|
||||
IAT_CHECK_EQ(result, 0xE85EA4DE);
|
||||
}
|
||||
|
||||
{
|
||||
String s = "Test";
|
||||
u32 r1 = DataOps::Hash_xxHash(s);
|
||||
u32 r2 =
|
||||
DataOps::Hash_xxHash(Span<const u8>((const u8 *)s.data(), s.size()));
|
||||
const String s = "Test";
|
||||
const u32 r1 = DataOps::hash_xxhash(s);
|
||||
const u32 r2 = DataOps::hash_xxhash(
|
||||
Span<const u8>(reinterpret_cast<const u8 *>(s.data()), s.size()));
|
||||
IAT_CHECK_EQ(r1, r2);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestHash_FNV1A() {
|
||||
auto test_hash_fnv1a() -> bool {
|
||||
{
|
||||
String s = "123456789";
|
||||
u32 result =
|
||||
DataOps::Hash_FNV1A(Span<const u8>((const u8 *)s.data(), s.size()));
|
||||
const String s = "123456789";
|
||||
const u32 result = DataOps::hash_fnv1a(
|
||||
Span<const u8>(reinterpret_cast<const u8 *>(s.data()), s.size()));
|
||||
IAT_CHECK_EQ(result, 0xbb86b11c);
|
||||
}
|
||||
|
||||
{
|
||||
u32 result = DataOps::Hash_FNV1A(Span<const u8>{});
|
||||
const u32 result = DataOps::hash_fnv1a(Span<const u8>{});
|
||||
IAT_CHECK_EQ(result, 0x811C9DC5);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Registration
|
||||
// -------------------------------------------------------------------------
|
||||
IAT_BEGIN_TEST_LIST()
|
||||
IAT_ADD_TEST(TestCRC32);
|
||||
IAT_ADD_TEST(TestHash_FNV1A);
|
||||
IAT_ADD_TEST(TestHash_xxHash);
|
||||
IAT_ADD_TEST(test_crc32);
|
||||
IAT_ADD_TEST(test_hash_fnv1a);
|
||||
IAT_ADD_TEST(test_hash_xxhash);
|
||||
IAT_END_TEST_LIST()
|
||||
|
||||
IAT_END_BLOCK()
|
||||
|
||||
IAT_REGISTER_ENTRY(Core, DataOps)
|
||||
IAT_REGISTER_ENTRY(Core, DataOps)
|
||||
Reference in New Issue
Block a user