2006-05-21 17:14:11 +00:00
|
|
|
|
2009-03-09 20:56:23 +00:00
|
|
|
// Copyright 2006-2009 Daniel James.
|
2022-10-24 11:31:25 -07:00
|
|
|
// Copyright 2022 Christian Mazakas.
|
2006-07-01 22:31:26 +00:00
|
|
|
// 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)
|
2006-05-21 17:14:11 +00:00
|
|
|
|
|
|
|
|
// This test checks the runtime requirements of containers.
|
|
|
|
|
|
2022-10-20 15:25:40 -07:00
|
|
|
#include "../helpers/unordered.hpp"
|
2012-04-08 15:29:15 +00:00
|
|
|
|
2008-03-24 17:03:15 +00:00
|
|
|
#include "../helpers/test.hpp"
|
2008-01-23 23:39:59 +00:00
|
|
|
#include <cstdlib>
|
2006-05-21 17:14:11 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include "../helpers/equivalent.hpp"
|
|
|
|
|
|
2017-02-19 13:05:17 +00:00
|
|
|
template <class X> void simple_test(X const& a)
|
2006-05-21 17:14:11 +00:00
|
|
|
{
|
2017-06-11 20:55:59 +01:00
|
|
|
test::unordered_equivalence_tester<X> equivalent(a);
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
X u;
|
|
|
|
|
BOOST_TEST(u.size() == 0);
|
|
|
|
|
BOOST_TEST(X().size() == 0);
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
BOOST_TEST(equivalent(X(a)));
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
X u(a);
|
|
|
|
|
BOOST_TEST(equivalent(u));
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
X u = a;
|
|
|
|
|
BOOST_TEST(equivalent(u));
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
X b(a);
|
|
|
|
|
BOOST_TEST(b.begin() == const_cast<X const&>(b).cbegin());
|
|
|
|
|
BOOST_TEST(b.end() == const_cast<X const&>(b).cend());
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
X b(a);
|
|
|
|
|
X c;
|
|
|
|
|
BOOST_TEST(equivalent(b));
|
|
|
|
|
BOOST_TEST(c.empty());
|
|
|
|
|
b.swap(c);
|
|
|
|
|
BOOST_TEST(b.empty());
|
|
|
|
|
BOOST_TEST(equivalent(c));
|
|
|
|
|
b.swap(c);
|
|
|
|
|
BOOST_TEST(c.empty());
|
|
|
|
|
BOOST_TEST(equivalent(b));
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
X u;
|
|
|
|
|
X& r = u;
|
|
|
|
|
BOOST_TEST(&(r = r) == &r);
|
2009-08-30 16:42:28 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_TEST(r.empty());
|
|
|
|
|
BOOST_TEST(&(r = a) == &r);
|
|
|
|
|
BOOST_TEST(equivalent(r));
|
|
|
|
|
BOOST_TEST(&(r = r) == &r);
|
|
|
|
|
BOOST_TEST(equivalent(r));
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
2018-01-27 09:39:59 +00:00
|
|
|
BOOST_TEST(a.size() == static_cast<typename X::size_type>(
|
2017-06-11 20:55:59 +01:00
|
|
|
std::distance(a.begin(), a.end())));
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
BOOST_TEST(a.empty() == (a.size() == 0));
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
{
|
|
|
|
|
BOOST_TEST(a.empty() == (a.begin() == a.end()));
|
|
|
|
|
X u;
|
|
|
|
|
BOOST_TEST(u.begin() == u.end());
|
|
|
|
|
}
|
2006-05-21 17:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-09 12:34:47 +01:00
|
|
|
UNORDERED_AUTO_TEST (simple_tests) {
|
2017-06-11 20:55:59 +01:00
|
|
|
using namespace std;
|
|
|
|
|
srand(14878);
|
2008-01-10 22:30:46 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_set.\n";
|
2022-10-12 15:19:11 -07:00
|
|
|
#ifdef BOOST_UNORDERED_FOA_TESTS
|
|
|
|
|
boost::unordered_flat_set<int> set;
|
|
|
|
|
#else
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_set<int> set;
|
2022-10-12 15:19:11 -07:00
|
|
|
#endif
|
2017-06-11 20:55:59 +01:00
|
|
|
simple_test(set);
|
2009-08-30 16:42:28 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
set.insert(1);
|
|
|
|
|
set.insert(2);
|
|
|
|
|
set.insert(1456);
|
|
|
|
|
simple_test(set);
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2022-10-12 15:19:11 -07:00
|
|
|
#ifndef BOOST_UNORDERED_FOA_TESTS
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multiset.\n";
|
|
|
|
|
boost::unordered_multiset<int> multiset;
|
|
|
|
|
simple_test(multiset);
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
for (int i1 = 0; i1 < 1000; ++i1) {
|
|
|
|
|
int count = rand() % 10, index = rand();
|
|
|
|
|
for (int j = 0; j < count; ++j)
|
|
|
|
|
multiset.insert(index);
|
|
|
|
|
}
|
|
|
|
|
simple_test(multiset);
|
2022-10-12 15:19:11 -07:00
|
|
|
#endif
|
2017-02-19 13:05:17 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_map.\n";
|
2022-10-12 15:19:11 -07:00
|
|
|
#ifdef BOOST_UNORDERED_FOA_TESTS
|
|
|
|
|
boost::unordered_flat_map<int, int> map;
|
|
|
|
|
#else
|
2017-06-11 20:55:59 +01:00
|
|
|
boost::unordered_map<int, int> map;
|
2022-10-12 15:19:11 -07:00
|
|
|
#endif
|
2008-01-10 22:30:46 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
for (int i2 = 0; i2 < 1000; ++i2) {
|
|
|
|
|
map.insert(std::pair<const int, int>(rand(), rand()));
|
|
|
|
|
}
|
|
|
|
|
simple_test(map);
|
2006-05-21 17:14:11 +00:00
|
|
|
|
2022-10-12 15:19:11 -07:00
|
|
|
#ifndef BOOST_UNORDERED_FOA_TESTS
|
2017-06-11 20:55:59 +01:00
|
|
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Test unordered_multimap.\n";
|
|
|
|
|
boost::unordered_multimap<int, int> multimap;
|
2008-01-10 22:30:46 +00:00
|
|
|
|
2017-06-11 20:55:59 +01:00
|
|
|
for (int i3 = 0; i3 < 1000; ++i3) {
|
|
|
|
|
int count = rand() % 10, index = rand();
|
|
|
|
|
for (int j = 0; j < count; ++j)
|
|
|
|
|
multimap.insert(std::pair<const int, int>(index, rand()));
|
|
|
|
|
}
|
|
|
|
|
simple_test(multimap);
|
2022-10-12 15:19:11 -07:00
|
|
|
#endif
|
2006-05-21 17:14:11 +00:00
|
|
|
}
|
2008-03-24 17:03:15 +00:00
|
|
|
|
|
|
|
|
RUN_TESTS()
|