Add erase_tests

This commit is contained in:
Christian Mazakas
2022-10-04 10:56:26 -07:00
parent 21872edf83
commit 9280e13697
2 changed files with 41 additions and 4 deletions

View File

@ -100,4 +100,5 @@ run unordered/constructor_tests.cpp : : : <cxxstd>98:<build>no <cxxstd>03:<build
run unordered/copy_tests.cpp : : : <cxxstd>98:<build>no <cxxstd>03:<build>no <cxxstd>11:<build>no <define>BOOST_UNORDERED_FOA_TESTS : foa_copy_tests ;
run unordered/assign_tests.cpp : : : <cxxstd>98:<build>no <cxxstd>03:<build>no <cxxstd>11:<build>no <define>BOOST_UNORDERED_FOA_TESTS : foa_assign_tests ;
run unordered/insert_tests.cpp : : : <cxxstd>98:<build>no <cxxstd>03:<build>no <cxxstd>11:<build>no <define>BOOST_UNORDERED_FOA_TESTS : foa_insert_tests ;
run unordered/erase_tests.cpp : : : <cxxstd>98:<build>no <cxxstd>03:<build>no <cxxstd>11:<build>no <define>BOOST_UNORDERED_FOA_TESTS : foa_erase_tests ;
run unordered/find_tests.cpp : : : <cxxstd>98:<build>no <cxxstd>03:<build>no <cxxstd>11:<build>no <define>BOOST_UNORDERED_FOA_TESTS : foa_find_tests ;

View File

@ -5,8 +5,13 @@
// clang-format off
#include "../helpers/prefix.hpp"
#ifdef BOOST_UNORDERED_FOA_TESTS
#include <boost/unordered_flat_set.hpp>
#include <boost/unordered_flat_map.hpp>
#else
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
#endif
#include "../helpers/postfix.hpp"
// clang-format on
@ -27,7 +32,9 @@ namespace erase_tests {
template <class Container>
void erase_tests1(Container*, test::random_generator generator)
{
#ifndef BOOST_UNORDERED_FOA_TESTS
typedef typename Container::iterator iterator;
#endif
typedef typename Container::const_iterator c_iterator;
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Erase by key.\n";
@ -61,9 +68,13 @@ namespace erase_tests {
while (size > 0 && !x.empty()) {
typename Container::key_type key = test::get_key<Container>(*x.begin());
std::size_t count = x.count(key);
#ifdef BOOST_UNORDERED_FOA_TESTS
x.erase(x.begin());
#else
iterator pos = x.erase(x.begin());
--size;
BOOST_TEST(pos == x.begin());
#endif
--size;
BOOST_TEST(x.count(key) == count - 1);
BOOST_TEST(x.size() == size);
if (++iterations % 20 == 0)
@ -93,10 +104,15 @@ namespace erase_tests {
typename Container::key_type key = test::get_key<Container>(*pos);
std::size_t count = x.count(key);
BOOST_TEST(count > 0);
#ifdef BOOST_UNORDERED_FOA_TESTS
x.erase(pos);
--size;
#else
BOOST_TEST(next == x.erase(pos));
--size;
if (size > 0)
BOOST_TEST(index == 0 ? next == x.begin() : next == test::next(prev));
#endif
BOOST_TEST(x.count(key) == count - 1);
if (x.count(key) != count - 1) {
BOOST_LIGHTWEIGHT_TEST_OSTREAM << count << " => " << x.count(key)
@ -185,7 +201,11 @@ namespace erase_tests {
while (size > 0 && !x.empty()) {
typename Container::key_type key = test::get_key<Container>(*x.begin());
std::size_t count = x.count(key);
#ifdef BOOST_UNORDERED_FOA_TESTS
x.erase(x.begin());
#else
x.quick_erase(x.begin());
#endif
--size;
BOOST_TEST(x.count(key) == count - 1);
BOOST_TEST(x.size() == size);
@ -216,7 +236,11 @@ namespace erase_tests {
typename Container::key_type key = test::get_key<Container>(*pos);
std::size_t count = x.count(key);
BOOST_TEST(count > 0);
#ifdef BOOST_UNORDERED_FOA_TESTS
x.erase(pos);
#else
x.quick_erase(pos);
#endif
--size;
if (size > 0)
BOOST_TEST(index == 0 ? next == x.begin() : next == test::next(prev));
@ -246,6 +270,20 @@ namespace erase_tests {
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "\n";
}
using test::default_generator;
using test::generate_collisions;
using test::limited_range;
#ifdef BOOST_UNORDERED_FOA_TESTS
boost::unordered_flat_set<test::object, test::hash, test::equal_to,
test::allocator1<test::object> >* test_set;
boost::unordered_flat_map<test::object, test::object, test::hash,
test::equal_to, test::allocator1<test::object> >* test_map;
UNORDERED_TEST(
erase_tests1, ((test_set)(test_map))(
(default_generator)(generate_collisions)(limited_range)))
#else
boost::unordered_set<test::object, test::hash, test::equal_to,
test::allocator1<test::object> >* test_set;
boost::unordered_multiset<test::object, test::hash, test::equal_to,
@ -255,13 +293,11 @@ namespace erase_tests {
boost::unordered_multimap<test::object, test::object, test::hash,
test::equal_to, test::allocator2<test::object> >* test_multimap;
using test::default_generator;
using test::generate_collisions;
using test::limited_range;
UNORDERED_TEST(
erase_tests1, ((test_set)(test_multiset)(test_map)(test_multimap))(
(default_generator)(generate_collisions)(limited_range)))
#endif
}
RUN_TESTS()