Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/multi_index/test/test_comparison.cpp @ 12

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

added boost

File size: 2.3 KB
Line 
1/* Boost.MultiIndex test for comparison functions.
2 *
3 * Copyright 2003-2005 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_comparison.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
20template<typename Value>
21struct lookup_list{
22  typedef multi_index_container<
23    Value,
24    indexed_by<
25      sequenced<>,
26      ordered_non_unique<identity<Value> >
27    >
28  > type;
29};
30
31void test_comparison()
32{
33  employee_set              es;
34  employee_set_by_age&      i2=get<2>(es);
35  employee_set_as_inserted& i3=get<3>(es);
36  es.insert(employee(0,"Joe",31,1123));
37  es.insert(employee(1,"Robert",27,5601));
38  es.insert(employee(2,"John",40,7889));
39  es.insert(employee(3,"Albert",20,9012));
40  es.insert(employee(4,"John",57,1002));
41
42  employee_set              es2;
43  employee_set_by_age&      i22=get<age>(es2);
44  employee_set_as_inserted& i32=get<3>(es2);
45  es.insert(employee(0,"Joe",31,1123));
46  es.insert(employee(1,"Robert",27,5601));
47  es.insert(employee(2,"John",40,7889));
48  es.insert(employee(3,"Albert",20,9012));
49
50  BOOST_CHECK(es==es&&es<=es&&es>=es&&
51              i22==i22&&i22<=i22&&i22>=i22&&
52              i32==i32&&i32<=i32&&i32>=i32);
53  BOOST_CHECK(es!=es2&&es2<es&&es>es2&&!(es<=es2)&&!(es2>=es));
54  BOOST_CHECK(i2!=i22&&i22<i2&&i2>i22&&!(i2<=i22)&&!(i22>=i2));
55  BOOST_CHECK(i3!=i32&&i32<i3&&i3>i32&&!(i3<=i32)&&!(i32>=i3));
56
57  lookup_list<int>::type  l1;
58  lookup_list<char>::type l2;
59  lookup_list<long>::type l3;
60
61  l1.push_back(3);
62  l1.push_back(4);
63  l1.push_back(5);
64  l1.push_back(1);
65  l1.push_back(2);
66
67  l2.push_back(char(3));
68  l2.push_back(char(4));
69  l2.push_back(char(5));
70  l2.push_back(char(1));
71  l2.push_back(char(2));
72
73  l3.push_back(long(3));
74  l3.push_back(long(4));
75  l3.push_back(long(5));
76  l3.push_back(long(1));
77
78  BOOST_CHECK(l1==l2&&l1<=l2&&l1>=l2);
79  BOOST_CHECK(
80    get<1>(l1)==get<1>(l2)&&get<1>(l1)<=get<1>(l2)&&get<1>(l1)>=get<1>(l2));
81  BOOST_CHECK(l1!=l3&&l3<l1&&l1>l3);
82  BOOST_CHECK(
83    get<1>(l1)!=get<1>(l3)&&get<1>(l1)<get<1>(l3)&&get<1>(l3)>get<1>(l1));
84}
Note: See TracBrowser for help on using the repository browser.