mirror of
https://github.com/boostorg/container_hash.git
synced 2026-02-07 07:34:38 +01:00
Boster.Test which makes it easier to switch to take advantage of Boost.Test's extra testing facilities. Merged revisions 44420 via svnmerge from https://svn.boost.org/svn/boost/branches/unordered/trunk ........ r44420 | danieljames | 2008-04-14 19:02:03 +0100 (Mon, 14 Apr 2008) | 1 line Use Boost.Test's minimal test library. ........ [SVN r44487]
94 lines
2.6 KiB
C++
94 lines
2.6 KiB
C++
|
|
// Copyright 2006-2008 Daniel James.
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
// This checks that template code implemented using hash_fwd will work.
|
|
|
|
#include "./hash_fwd_test.hpp"
|
|
|
|
#include <boost/test/minimal.hpp>
|
|
|
|
#if defined(TEST_EXTENSIONS) && !defined(TEST_STD_INCLUDES)
|
|
|
|
#include <boost/functional/hash.hpp>
|
|
#include <string>
|
|
|
|
void fwd_test1()
|
|
{
|
|
test::test_type1<int> x(5);
|
|
test::test_type1<std::string> y("Test");
|
|
|
|
HASH_NAMESPACE::hash<int> hasher_int;
|
|
HASH_NAMESPACE::hash<std::string> hasher_string;
|
|
HASH_NAMESPACE::hash<test::test_type1<int> > hasher_test_int;
|
|
HASH_NAMESPACE::hash<test::test_type1<std::string> > hasher_test_string;
|
|
|
|
BOOST_CHECK(hasher_int(5) == hasher_test_int(x));
|
|
BOOST_CHECK(hasher_string("Test") == hasher_test_string(y));
|
|
}
|
|
|
|
void fwd_test2()
|
|
{
|
|
test::test_type2<int> x(5, 10);
|
|
test::test_type2<std::string> y("Test1", "Test2");
|
|
|
|
std::size_t seed1 = 0;
|
|
HASH_NAMESPACE::hash_combine(seed1, 5);
|
|
HASH_NAMESPACE::hash_combine(seed1, 10);
|
|
|
|
std::size_t seed2 = 0;
|
|
HASH_NAMESPACE::hash_combine(seed2, std::string("Test1"));
|
|
HASH_NAMESPACE::hash_combine(seed2, std::string("Test2"));
|
|
|
|
HASH_NAMESPACE::hash<test::test_type2<int> > hasher_test_int;
|
|
HASH_NAMESPACE::hash<test::test_type2<std::string> > hasher_test_string;
|
|
|
|
BOOST_CHECK(seed1 == hasher_test_int(x));
|
|
BOOST_CHECK(seed2 == hasher_test_string(y));
|
|
}
|
|
|
|
void fwd_test3()
|
|
{
|
|
std::vector<int> values1;
|
|
values1.push_back(10);
|
|
values1.push_back(15);
|
|
values1.push_back(20);
|
|
values1.push_back(3);
|
|
|
|
std::vector<std::string> values2;
|
|
values2.push_back("Chico");
|
|
values2.push_back("Groucho");
|
|
values2.push_back("Harpo");
|
|
values2.push_back("Gummo");
|
|
values2.push_back("Zeppo");
|
|
|
|
test::test_type3<int> x(values1.begin(), values1.end());
|
|
test::test_type3<std::string> y(values2.begin(), values2.end());
|
|
|
|
std::size_t seed1 = HASH_NAMESPACE::hash_range(values1.begin(), values1.end());
|
|
HASH_NAMESPACE::hash_range(seed1, values1.begin(), values1.end());
|
|
|
|
std::size_t seed2 = HASH_NAMESPACE::hash_range(values2.begin(), values2.end());
|
|
HASH_NAMESPACE::hash_range(seed2, values2.begin(), values2.end());
|
|
|
|
HASH_NAMESPACE::hash<test::test_type3<int> > hasher_test_int;
|
|
HASH_NAMESPACE::hash<test::test_type3<std::string> > hasher_test_string;
|
|
|
|
BOOST_CHECK(seed1 == hasher_test_int(x));
|
|
BOOST_CHECK(seed2 == hasher_test_string(y));
|
|
}
|
|
|
|
#endif
|
|
|
|
int test_main(int, char**)
|
|
{
|
|
#ifdef TEST_EXTENSIONS
|
|
fwd_test1();
|
|
fwd_test2();
|
|
fwd_test3();
|
|
#endif
|
|
return 0;
|
|
}
|
|
|