]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multi_index/test/test_comparison.cpp
1 /* Boost.MultiIndex test for comparison functions.
3 * Copyright 2003-2013 Joaquin M Lopez Munoz.
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)
8 * See http://www.boost.org/libs/multi_index for library home page.
11 #include "test_comparison.hpp"
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 "pair_of_ints.hpp"
17 #include <boost/detail/lightweight_test.hpp>
19 using namespace boost::multi_index
;
21 template<typename Value
>
23 typedef multi_index_container
<
27 ordered_non_unique
<identity
<Value
> >
32 template<typename Value
>
34 typedef multi_index_container
<
38 ordered_non_unique
<identity
<Value
> >
43 void test_comparison()
46 employee_set_by_name
& i1
=get
<1>(es
);
47 employee_set_by_age
& i2
=get
<2>(es
);
48 employee_set_as_inserted
& i3
=get
<3>(es
);
49 employee_set_by_ssn
& i4
=get
<4>(es
);
50 employee_set_randomly
& i5
=get
<5>(es
);
51 es
.insert(employee(0,"Joe",31,1123));
52 es
.insert(employee(1,"Robert",27,5601));
53 es
.insert(employee(2,"John",40,7889));
54 es
.insert(employee(3,"Albert",20,9012));
55 es
.insert(employee(4,"John",57,1002));
58 employee_set_by_name
& i12
=get
<by_name
>(es2
);
59 employee_set_by_age
& i22
=get
<age
>(es2
);
60 employee_set_as_inserted
& i32
=get
<3>(es2
);
61 employee_set_by_ssn
& i42
=get
<4>(es2
);
62 employee_set_randomly
& i52
=get
<5>(es2
);
63 es2
.insert(employee(0,"Joe",31,1123));
64 es2
.insert(employee(1,"Robert",27,5601));
65 es2
.insert(employee(2,"John",40,7889));
66 es2
.insert(employee(3,"Albert",20,9012));
68 BOOST_TEST(es
==es
&&es
<=es
&&es
>=es
&&
70 i22
==i22
&&i22
<=i22
&&i22
>=i22
&&
71 i32
==i32
&&i32
<=i32
&&i32
>=i32
&&
73 i52
==i52
&&i52
<=i52
&&i52
>=i52
);
74 BOOST_TEST(es
!=es2
&&es2
<es
&&es
>es2
&&!(es
<=es2
)&&!(es2
>=es
));
76 BOOST_TEST(i2
!=i22
&&i22
<i2
&&i2
>i22
&&!(i2
<=i22
)&&!(i22
>=i2
));
77 BOOST_TEST(i3
!=i32
&&i32
<i3
&&i3
>i32
&&!(i3
<=i32
)&&!(i32
>=i3
));
79 BOOST_TEST(i5
!=i52
&&i52
<i5
&&i5
>i52
&&!(i5
<=i52
)&&!(i52
>=i5
));
81 multi_index_container
<
84 hashed_non_unique
<BOOST_MULTI_INDEX_MEMBER(pair_of_ints
,int,first
)>
87 hc1
.insert(pair_of_ints(0,0));
88 hc1
.insert(pair_of_ints(0,1));
89 hc1
.insert(pair_of_ints(0,2));
90 hc1
.insert(pair_of_ints(0,3));
91 hc1
.insert(pair_of_ints(1,0));
92 hc1
.insert(pair_of_ints(1,1));
94 hc2
.insert(pair_of_ints(0,2));
95 hc2
.insert(pair_of_ints(0,1));
96 hc2
.insert(pair_of_ints(1,1));
97 hc2
.insert(pair_of_ints(1,0));
98 hc2
.insert(pair_of_ints(0,3));
99 hc2
.insert(pair_of_ints(0,0));
100 BOOST_TEST(hc1
==hc2
);
102 hc1
.insert(pair_of_ints(0,4));
103 hc2
.insert(pair_of_ints(0,5));
104 BOOST_TEST(hc1
!=hc2
);
106 lookup_list
<int>::type l1
;
107 lookup_list
<char>::type l2
;
108 lookup_vector
<char>::type l3
;
109 lookup_list
<long>::type l4
;
110 lookup_vector
<long>::type l5
;
118 l2
.push_back(char(3));
119 l2
.push_back(char(4));
120 l2
.push_back(char(5));
121 l2
.push_back(char(1));
122 l2
.push_back(char(2));
124 l3
.push_back(char(3));
125 l3
.push_back(char(4));
126 l3
.push_back(char(5));
127 l3
.push_back(char(1));
128 l3
.push_back(char(2));
130 l4
.push_back(long(3));
131 l4
.push_back(long(4));
132 l4
.push_back(long(5));
133 l4
.push_back(long(1));
135 l5
.push_back(long(3));
136 l5
.push_back(long(4));
137 l5
.push_back(long(5));
138 l5
.push_back(long(1));
140 BOOST_TEST(l1
==l2
&&l1
<=l2
&&l1
>=l2
);
142 get
<1>(l1
)==get
<1>(l2
)&&get
<1>(l1
)<=get
<1>(l2
)&&get
<1>(l1
)>=get
<1>(l2
));
144 get
<1>(l1
)==get
<1>(l3
)&&get
<1>(l1
)<=get
<1>(l3
)&&get
<1>(l1
)>=get
<1>(l3
));
145 BOOST_TEST(l1
!=l4
&&l4
<l1
&&l1
>l4
);
147 get
<1>(l1
)!=get
<1>(l4
)&&get
<1>(l1
)<get
<1>(l4
)&&get
<1>(l4
)>get
<1>(l1
));
148 BOOST_TEST(l3
!=l5
&&l5
<l3
&&l3
>l5
);
150 get
<1>(l3
)!=get
<1>(l5
)&&get
<1>(l3
)<get
<1>(l5
)&&get
<1>(l5
)>get
<1>(l3
));