Line data Source code
1 : // Author(s): Maurice Laveaux 2 : // Copyright: see the accompanying file COPYING or copy at 3 : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING 4 : // 5 : // Distributed under the Boost Software License, Version 1.0. 6 : // (See accompanying file LICENSE_1_0.txt or copy at 7 : // http://www.boost.org/LICENSE_1_0.txt) 8 : // 9 : 10 : #include "mcrl2/utilities/detail/bucket_list.h" 11 : 12 : #define BOOST_AUTO_TEST_MAIN 13 : #include <boost/test/included/unit_test.hpp> 14 : 15 : using namespace mcrl2::utilities::detail; 16 : 17 : template<typename Element, 18 : typename Allocator> 19 3 : std::size_t length(bucket_list<Element, Allocator>& list) 20 : { 21 3 : std::size_t length = 0; 22 196 : for (auto& element : list) 23 : { 24 : (void)element; 25 190 : ++length; 26 : } 27 3 : return length; 28 : } 29 : 30 2 : BOOST_AUTO_TEST_CASE(test_list) 31 : { 32 : using Bucket = bucket_list<int, std::allocator<int>>; 33 1 : Bucket::NodeAllocator allocator; 34 1 : Bucket list; 35 : 36 : /// Allocate and construct various nodes for in the list. 37 101 : for (int i = 0; i < 100; ++i) 38 : { 39 100 : list.emplace_front(allocator, i); 40 : } 41 : 42 1 : BOOST_CHECK_EQUAL(length(list), 100); 43 : 44 : /// Erase the first 10 elements. 45 1 : std::size_t count = 10; 46 10 : for (Bucket::const_iterator it = list.before_begin(); it != list.end();) 47 : { 48 10 : it = list.erase_after(allocator, list.before_begin()); 49 10 : --count; 50 10 : if (count == 0) 51 : { 52 1 : break; 53 : } 54 : } 55 : 56 1 : BOOST_CHECK_EQUAL(length(list), 90); 57 : 58 : /// Clean up the remaining nodes. 59 91 : for (Bucket::const_iterator it = list.before_begin(); it != list.end();) 60 : { 61 90 : it = list.erase_after(allocator, list.before_begin()); 62 : } 63 : 64 1 : BOOST_CHECK_EQUAL(length(list), 0); 65 1 : }