Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/multi_index/test/test_basic.cpp @ 29

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

updated boost from 1_33_1 to 1_34_1

File size: 2.0 KB
Line 
1/* Boost.MultiIndex basic test.
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_basic.hpp"
12
13#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
14#include <algorithm>
15#include <vector>
16#include "pre_multi_index.hpp"
17#include "employee.hpp"
18#include <boost/test/test_tools.hpp>
19
20using namespace boost::multi_index;
21
22struct less_by_employee_age
23{
24  bool operator()(const employee& e1,const employee& e2)const
25  {
26    return e1.age<e2.age;
27  }
28};
29
30void test_basic()
31{
32  employee_set          es;
33  std::vector<employee> v;
34
35#if defined(BOOST_NO_MEMBER_TEMPLATES)
36  employee_set_by_name& i1=get<by_name>(es);
37#else
38  employee_set_by_name& i1=es.get<by_name>();
39#endif
40
41  const employee_set_by_age& i2=get<2>(es);
42  employee_set_as_inserted&  i3=get<3>(es);
43  employee_set_by_ssn&       i4=get<ssn>(es);
44  employee_set_randomly&     i5=get<randomly>(es);
45
46  es.insert(employee(0,"Joe",31,1123));
47  es.insert(employee(5,"Anna",41,1123));      /* clash*/
48  i1.insert(employee(1,"Robert",27,5601));
49  es.insert(employee(2,"John",40,7889));
50  i3.push_back(employee(3,"Albert",20,9012));
51  i4.insert(employee(4,"John",57,1002));
52  i5.push_back(employee(0,"Andrew",60,2302)); /* clash */
53
54  v.push_back(employee(0,"Joe",31,1123));
55  v.push_back(employee(1,"Robert",27,5601));
56  v.push_back(employee(2,"John",40,7889));
57  v.push_back(employee(3,"Albert",20,9012));
58  v.push_back(employee(4,"John",57,1002));
59
60  {
61    /* by insertion order */
62
63    BOOST_CHECK(std::equal(i3.begin(),i3.end(),v.begin()));
64    BOOST_CHECK(std::equal(i5.begin(),i5.end(),v.begin()));
65  }
66
67  {
68    /* by id */
69
70    std::sort(v.begin(),v.end());
71    BOOST_CHECK(std::equal(es.begin(),es.end(),v.begin()));
72  }
73
74  {
75    /* by age */
76
77    std::sort(v.begin(),v.end(),less_by_employee_age());
78    BOOST_CHECK(std::equal(i2.begin(),i2.end(),v.begin()));
79  }
80
81}
Note: See TracBrowser for help on using the repository browser.