From 2d0df035ea68e25a2eca7121e294bb0c054154c8 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 28 May 2011 17:44:52 -0400 Subject: [PATCH] Added a unit test for the new hashing functions. --HG-- rename : dlib/test/bridge.cpp => dlib/test/hash.cpp --- dlib/test/CMakeLists.txt | 1 + dlib/test/hash.cpp | 77 ++++++++++++++++++++++++++++++++++++++++ dlib/test/makefile | 1 + 3 files changed, 79 insertions(+) create mode 100644 dlib/test/hash.cpp diff --git a/dlib/test/CMakeLists.txt b/dlib/test/CMakeLists.txt index fabc79470..613a9099e 100644 --- a/dlib/test/CMakeLists.txt +++ b/dlib/test/CMakeLists.txt @@ -45,6 +45,7 @@ set (tests entropy_encoder_model.cpp geometry.cpp graph.cpp + hash.cpp hash_map.cpp hash_set.cpp hash_table.cpp diff --git a/dlib/test/hash.cpp b/dlib/test/hash.cpp new file mode 100644 index 000000000..94e579909 --- /dev/null +++ b/dlib/test/hash.cpp @@ -0,0 +1,77 @@ +// Copyright (C) 2011 Davis E. King (davis@dlib.net) +// License: Boost Software License See LICENSE.txt for the full license. + +#include +#include +#include +#include +#include + +#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 v(4); + v[0] = 'c'; + v[1] = 'a'; + v[2] = 't'; + v[3] = '!'; + + std::map 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; + + + +} + + + diff --git a/dlib/test/makefile b/dlib/test/makefile index 93b8cf3e5..95378fa9b 100644 --- a/dlib/test/makefile +++ b/dlib/test/makefile @@ -55,6 +55,7 @@ SRC += entropy_coder.cpp SRC += entropy_encoder_model.cpp SRC += geometry.cpp SRC += graph.cpp +SRC += hash.cpp SRC += hash_map.cpp SRC += hash_set.cpp SRC += hash_table.cpp