diff --git a/test/unordered/simple_tests.cpp b/test/unordered/simple_tests.cpp index dbbf7a48..a446f7c7 100644 --- a/test/unordered/simple_tests.cpp +++ b/test/unordered/simple_tests.cpp @@ -1,6 +1,6 @@ // Copyright 2006-2009 Daniel James. -// Copyright 2022 Christian Mazakas. +// Copyright 2022-2023 Christian Mazakas. // 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) @@ -8,10 +8,13 @@ #include "../helpers/unordered.hpp" -#include "../helpers/test.hpp" -#include -#include #include "../helpers/equivalent.hpp" +#include "../helpers/generators.hpp" +#include "../helpers/test.hpp" +#include +#include + +test::seed_t initialize_seed(14878); template void simple_test(X const& a) { @@ -84,59 +87,76 @@ template void simple_test(X const& a) } } -UNORDERED_AUTO_TEST (simple_tests) { - using namespace std; - srand(14878); +template static void simple_set_tests(X*) +{ + X x; - BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set.\n"; -#ifdef BOOST_UNORDERED_FOA_TESTS - boost::unordered_flat_set set; -#else - boost::unordered_set set; -#endif - simple_test(set); + simple_test(x); - set.insert(1); - set.insert(2); - set.insert(1456); - simple_test(set); + x.insert(1); + x.insert(2); + x.insert(1456); + simple_test(x); +} #ifndef BOOST_UNORDERED_FOA_TESTS - BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset.\n"; - boost::unordered_multiset multiset; - simple_test(multiset); +template static void simple_multiset_tests(X*) +{ + X x; + simple_test(x); for (int i1 = 0; i1 < 1000; ++i1) { int count = rand() % 10, index = rand(); for (int j = 0; j < count; ++j) - multiset.insert(index); + x.insert(index); } - simple_test(multiset); + simple_test(x); +} #endif - BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_map.\n"; -#ifdef BOOST_UNORDERED_FOA_TESTS - boost::unordered_flat_map map; -#else - boost::unordered_map map; -#endif +template static void simple_map_tests(X*) +{ + X x; for (int i2 = 0; i2 < 1000; ++i2) { - map.insert(std::pair(rand(), rand())); + x.insert(std::pair(rand(), rand())); } - simple_test(map); + simple_test(x); +} #ifndef BOOST_UNORDERED_FOA_TESTS - BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multimap.\n"; - boost::unordered_multimap multimap; +template static void simple_multimap_tests(X*) +{ + X x; for (int i3 = 0; i3 < 1000; ++i3) { int count = rand() % 10, index = rand(); for (int j = 0; j < count; ++j) - multimap.insert(std::pair(index, rand())); + x.insert(std::pair(index, rand())); } - simple_test(multimap); -#endif + simple_test(x); } +#endif + +#ifdef BOOST_UNORDERED_FOA_TESTS +static boost::unordered_flat_set* flat_set; +static boost::unordered_flat_map* flat_map; +static boost::unordered_node_set* node_set; +static boost::unordered_node_map* node_map; + +UNORDERED_TEST(simple_map_tests, ((flat_map)(node_map))) +UNORDERED_TEST(simple_set_tests, ((flat_set)(node_set))) +#else +static boost::unordered_set* set; +static boost::unordered_map* map; +static boost::unordered_multiset* multiset; +static boost::unordered_multimap* multimap; + +UNORDERED_TEST(simple_set_tests, ((set))) +UNORDERED_TEST(simple_map_tests, ((map))) +UNORDERED_TEST(simple_multiset_tests, ((multiset))) +UNORDERED_TEST(simple_multimap_tests, ((multimap))) + +#endif RUN_TESTS()