Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/multi_index/test/test_capacity.cpp @ 35

Last change on this file since 35 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.1 KB
Line 
1/* Boost.MultiIndex test for capacity memfuns.
2 *
3 * Copyright 2003-2006 Joaquín M López Muñoz.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 * See http://www.boost.org/libs/multi_index for library home page.
9 */
10
11#include "test_capacity.hpp"
12
13#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
14#include "pre_multi_index.hpp"
15#include "employee.hpp"
16#include <boost/test/test_tools.hpp>
17
18using namespace boost::multi_index;
19
20void test_capacity()
21{
22  employee_set es;
23
24  es.insert(employee(0,"Joe",31,1123));
25  es.insert(employee(1,"Robert",27,5601));
26  es.insert(employee(2,"John",40,7889));
27  es.insert(employee(3,"Albert",20,9012));
28  es.insert(employee(4,"John",57,1002));
29
30  BOOST_CHECK(!es.empty());
31  BOOST_CHECK(es.size()==5);
32  BOOST_CHECK(es.size()<=es.max_size());
33
34  es.erase(es.begin());
35  BOOST_CHECK(!get<name>(es).empty());
36  BOOST_CHECK(get<name>(es).size()==4);
37  BOOST_CHECK(get<name>(es).size()<=get<name>(es).max_size());
38
39  es.erase(es.begin());
40  BOOST_CHECK(!get<as_inserted>(es).empty());
41  BOOST_CHECK(get<as_inserted>(es).size()==3);
42  BOOST_CHECK(get<as_inserted>(es).size()<=get<as_inserted>(es).max_size());
43
44  multi_index_container<int,indexed_by<sequenced<> > > ss;
45
46  ss.resize(10);
47  BOOST_CHECK(ss.size()==10);
48  BOOST_CHECK(ss.size()<=ss.max_size());
49
50  ss.resize(20);
51  BOOST_CHECK(ss.size()==20);
52
53  ss.resize(5);
54  BOOST_CHECK(ss.size()==5);
55
56  multi_index_container<int,indexed_by<random_access<> > > rs;
57
58  rs.resize(10);
59  BOOST_CHECK(rs.size()==10);
60  BOOST_CHECK(rs.size()<=rs.max_size());
61  BOOST_CHECK(rs.size()<=rs.capacity());
62
63  rs.resize(20);
64  BOOST_CHECK(rs.size()==20);
65  BOOST_CHECK(rs.size()<=rs.capacity());
66
67  unsigned int c=rs.capacity();
68  rs.resize(5);
69  BOOST_CHECK(rs.size()==5);
70  BOOST_CHECK(rs.capacity()==c);
71
72  rs.reserve(100);
73  BOOST_CHECK(rs.size()==5);
74  BOOST_CHECK(rs.capacity()>=100);
75
76  c=rs.capacity();
77  rs.reserve(99);
78  BOOST_CHECK(rs.size()==5);
79  BOOST_CHECK(rs.capacity()==c);
80}
Note: See TracBrowser for help on using the repository browser.