1 | /* Boost.MultiIndex test for comparison functions. |
---|
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_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 | |
---|
18 | using namespace boost::multi_index; |
---|
19 | |
---|
20 | template<typename Value> |
---|
21 | struct 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 | |
---|
31 | template<typename Value> |
---|
32 | struct lookup_vector{ |
---|
33 | typedef multi_index_container< |
---|
34 | Value, |
---|
35 | indexed_by< |
---|
36 | random_access<>, |
---|
37 | ordered_non_unique<identity<Value> > |
---|
38 | > |
---|
39 | > type; |
---|
40 | }; |
---|
41 | |
---|
42 | void test_comparison() |
---|
43 | { |
---|
44 | employee_set es; |
---|
45 | employee_set_by_age& i2=get<2>(es); |
---|
46 | employee_set_as_inserted& i3=get<3>(es); |
---|
47 | employee_set_randomly& i5=get<5>(es); |
---|
48 | es.insert(employee(0,"Joe",31,1123)); |
---|
49 | es.insert(employee(1,"Robert",27,5601)); |
---|
50 | es.insert(employee(2,"John",40,7889)); |
---|
51 | es.insert(employee(3,"Albert",20,9012)); |
---|
52 | es.insert(employee(4,"John",57,1002)); |
---|
53 | |
---|
54 | employee_set es2; |
---|
55 | employee_set_by_age& i22=get<age>(es2); |
---|
56 | employee_set_as_inserted& i32=get<3>(es2); |
---|
57 | employee_set_randomly& i52=get<5>(es2); |
---|
58 | es2.insert(employee(0,"Joe",31,1123)); |
---|
59 | es2.insert(employee(1,"Robert",27,5601)); |
---|
60 | es2.insert(employee(2,"John",40,7889)); |
---|
61 | es2.insert(employee(3,"Albert",20,9012)); |
---|
62 | |
---|
63 | BOOST_CHECK(es==es&&es<=es&&es>=es&& |
---|
64 | i22==i22&&i22<=i22&&i22>=i22&& |
---|
65 | i32==i32&&i32<=i32&&i32>=i32&& |
---|
66 | i52==i52&&i52<=i52&&i52>=i52); |
---|
67 | BOOST_CHECK(es!=es2&&es2<es&&es>es2&&!(es<=es2)&&!(es2>=es)); |
---|
68 | BOOST_CHECK(i2!=i22&&i22<i2&&i2>i22&&!(i2<=i22)&&!(i22>=i2)); |
---|
69 | BOOST_CHECK(i3!=i32&&i32<i3&&i3>i32&&!(i3<=i32)&&!(i32>=i3)); |
---|
70 | BOOST_CHECK(i5!=i52&&i52<i5&&i5>i52&&!(i5<=i52)&&!(i52>=i5)); |
---|
71 | |
---|
72 | lookup_list<int>::type l1; |
---|
73 | lookup_list<char>::type l2; |
---|
74 | lookup_vector<char>::type l3; |
---|
75 | lookup_list<long>::type l4; |
---|
76 | lookup_vector<long>::type l5; |
---|
77 | |
---|
78 | l1.push_back(3); |
---|
79 | l1.push_back(4); |
---|
80 | l1.push_back(5); |
---|
81 | l1.push_back(1); |
---|
82 | l1.push_back(2); |
---|
83 | |
---|
84 | l2.push_back(char(3)); |
---|
85 | l2.push_back(char(4)); |
---|
86 | l2.push_back(char(5)); |
---|
87 | l2.push_back(char(1)); |
---|
88 | l2.push_back(char(2)); |
---|
89 | |
---|
90 | l3.push_back(char(3)); |
---|
91 | l3.push_back(char(4)); |
---|
92 | l3.push_back(char(5)); |
---|
93 | l3.push_back(char(1)); |
---|
94 | l3.push_back(char(2)); |
---|
95 | |
---|
96 | l4.push_back(long(3)); |
---|
97 | l4.push_back(long(4)); |
---|
98 | l4.push_back(long(5)); |
---|
99 | l4.push_back(long(1)); |
---|
100 | |
---|
101 | l5.push_back(long(3)); |
---|
102 | l5.push_back(long(4)); |
---|
103 | l5.push_back(long(5)); |
---|
104 | l5.push_back(long(1)); |
---|
105 | |
---|
106 | BOOST_CHECK(l1==l2&&l1<=l2&&l1>=l2); |
---|
107 | BOOST_CHECK( |
---|
108 | get<1>(l1)==get<1>(l2)&&get<1>(l1)<=get<1>(l2)&&get<1>(l1)>=get<1>(l2)); |
---|
109 | BOOST_CHECK( |
---|
110 | get<1>(l1)==get<1>(l3)&&get<1>(l1)<=get<1>(l3)&&get<1>(l1)>=get<1>(l3)); |
---|
111 | BOOST_CHECK(l1!=l4&&l4<l1&&l1>l4); |
---|
112 | BOOST_CHECK( |
---|
113 | get<1>(l1)!=get<1>(l4)&&get<1>(l1)<get<1>(l4)&&get<1>(l4)>get<1>(l1)); |
---|
114 | BOOST_CHECK(l3!=l5&&l5<l3&&l3>l5); |
---|
115 | BOOST_CHECK( |
---|
116 | get<1>(l3)!=get<1>(l5)&&get<1>(l3)<get<1>(l5)&&get<1>(l5)>get<1>(l3)); |
---|
117 | } |
---|