Commit 2d0df035 authored by Davis King's avatar Davis King

Added a unit test for the new hashing functions.

--HG--
rename : dlib/test/bridge.cpp => dlib/test/hash.cpp
parent ebbb1b68
...@@ -45,6 +45,7 @@ set (tests ...@@ -45,6 +45,7 @@ set (tests
entropy_encoder_model.cpp entropy_encoder_model.cpp
geometry.cpp geometry.cpp
graph.cpp graph.cpp
hash.cpp
hash_map.cpp hash_map.cpp
hash_set.cpp hash_set.cpp
hash_table.cpp hash_table.cpp
......
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <dlib/hash.h>
#include "tester.h"
namespace
{
using namespace test;
using namespace dlib;
using namespace std;
logger dlog("test.hash");
class test_hash : public tester
{
public:
test_hash (
) :
tester ("test_hash",
"Runs tests on the hash routines.")
{}
void perform_test (
)
{
std::string str1 = "some random string";
std::wstring str2 = L"another String!";
std::vector<unsigned char> v(4);
v[0] = 'c';
v[1] = 'a';
v[2] = 't';
v[3] = '!';
std::map<unsigned char, unsigned char> m;
m['c'] = 'C';
m['a'] = 'A';
m['t'] = 'T';
dlog << LINFO << "hash(str1): "<< hash(str1);
dlog << LINFO << "hash(str2): "<< hash(str2);
dlog << LINFO << "hash(v): "<< hash(v);
dlog << LINFO << "hash(m): "<< hash(m);
DLIB_TEST(hash(str1) == 1073638390);
DLIB_TEST(hash(str2) == 2413364589);
DLIB_TEST(hash(v) == 4054789286);
DLIB_TEST(hash(m) == 2865512303);
DLIB_TEST(murmur_hash3(&str1[0], str1.size(), 0) == 1073638390);
dlog << LINFO << "hash(str1,1): "<< hash(str1,1);
dlog << LINFO << "hash(str2,2): "<< hash(str2,2);
dlog << LINFO << "hash(v,3): "<< hash(v,3);
dlog << LINFO << "hash(m,3): "<< hash(m,4);
DLIB_TEST(hash(str1,1) == 2977753747);
DLIB_TEST(hash(str2,2) == 3656927287);
DLIB_TEST(hash(v,3) == 2127112268);
DLIB_TEST(hash(m,4) == 4200495810);
DLIB_TEST(murmur_hash3(&str1[0], str1.size(), 1) == 2977753747);
}
} a;
}
...@@ -55,6 +55,7 @@ SRC += entropy_coder.cpp ...@@ -55,6 +55,7 @@ SRC += entropy_coder.cpp
SRC += entropy_encoder_model.cpp SRC += entropy_encoder_model.cpp
SRC += geometry.cpp SRC += geometry.cpp
SRC += graph.cpp SRC += graph.cpp
SRC += hash.cpp
SRC += hash_map.cpp SRC += hash_map.cpp
SRC += hash_set.cpp SRC += hash_set.cpp
SRC += hash_table.cpp SRC += hash_table.cpp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment