• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2006-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include "./containers.hpp"
7 
8 #include "../helpers/helpers.hpp"
9 #include "../helpers/invariants.hpp"
10 #include "../helpers/random_values.hpp"
11 
12 test::seed_t initialize_seed(835193);
13 
14 template <class T> struct erase_test_base : public test::exception_base
15 {
16   test::random_values<T> values;
erase_test_baseerase_test_base17   erase_test_base(unsigned int count = 5) : values(count, test::limited_range)
18   {
19   }
20 
21   typedef T data_type;
22 
initerase_test_base23   data_type init() const { return T(values.begin(), values.end()); }
24 
BOOST_PREVENT_MACRO_SUBSTITUTIONerase_test_base25   void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x) const
26   {
27     std::string scope(test::scope);
28 
29     BOOST_TEST(scope.find("hash::") != std::string::npos ||
30                scope.find("equal_to::") != std::string::npos ||
31                scope == "operator==(object, object)");
32 
33     test::check_equivalent_keys(x);
34   }
35 };
36 
37 template <class T> struct erase_by_key_test1 : public erase_test_base<T>
38 {
runerase_by_key_test139   void run(T& x) const
40   {
41     typedef typename test::random_values<T>::const_iterator iterator;
42 
43     for (iterator it = this->values.begin(), end = this->values.end();
44          it != end; ++it) {
45       x.erase(test::get_key<T>(*it));
46     }
47 
48     DISABLE_EXCEPTIONS;
49     BOOST_TEST(x.empty());
50     test::check_equivalent_keys(x);
51   }
52 };
53 
54 EXCEPTION_TESTS((erase_by_key_test1), CONTAINER_SEQ)
55 RUN_TESTS()
56