sdbm_hash for utils

This commit is contained in:
2018-11-17 11:00:02 +07:00
parent 1952d958e4
commit d61d647f48
3 changed files with 75 additions and 6 deletions

View File

@@ -6,6 +6,27 @@
#define CATCH_CONFIG_MAIN
#include "_utils.hpp"
using namespace e2d;
TEST_CASE("utils") {
{
REQUIRE(utils::sdbm_hash("") == 0u);
REQUIRE(utils::sdbm_hash(1u, "") == 1u);
REQUIRE(utils::sdbm_hash<char>(nullptr, nullptr) == 0u);
REQUIRE(utils::sdbm_hash<char>(1u, nullptr, nullptr) == 1u);
const char* str1 = "hello";
const char* str2 = "hello";
REQUIRE(utils::sdbm_hash(str1) == utils::sdbm_hash(str2));
REQUIRE(utils::sdbm_hash(42u, str1) == utils::sdbm_hash(42u, str2));
REQUIRE(utils::sdbm_hash(
str1, str1 + std::strlen(str1)
) == utils::sdbm_hash(str2));
REQUIRE(utils::sdbm_hash(
42u, str1, str1 + std::strlen(str1)
) == utils::sdbm_hash(42u, str2));
}
}