]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/test/writing-test-ts/collection-comparison-test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / test / test / writing-test-ts / collection-comparison-test.cpp
1 // (C) Copyright Gennadiy Rozental 2015.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 /// @file
9 /// @brief tests collection comparison implementation
10 // ***************************************************************************
11
12 // Boost.Test
13 #define BOOST_TEST_MODULE Test collection`s comparisons
14 #include <boost/test/unit_test.hpp>
15 namespace tt = boost::test_tools;
16 namespace ut = boost::unit_test;
17
18 BOOST_TEST_SPECIALIZED_COLLECTION_COMPARE(std::vector<int>)
19
20 #define VALIDATE_OP( op ) \
21 { \
22 BOOST_TEST_INFO( "validating operator " #op ); \
23 bool expected = (c1 op c2); \
24 auto const& res = (tt::assertion::seed()->* c1 op c2).evaluate(); \
25 BOOST_TEST( expected == !!res ); \
26 } \
27 /**/
28
29 template<typename Col>
30 void
31 validate_comparisons(Col const& c1, Col const& c2 )
32 {
33 VALIDATE_OP( == )
34 VALIDATE_OP( != )
35 VALIDATE_OP( < )
36 VALIDATE_OP( > )
37 VALIDATE_OP( <= )
38 VALIDATE_OP( >= )
39 }
40
41 BOOST_AUTO_TEST_CASE( test_against_overloaded_comp_op )
42 {
43 std::vector<int> a{1, 2, 3};
44 std::vector<int> b{1, 3, 2};
45 std::vector<int> c{1, 2, 3};
46 std::vector<int> d{1, 2, 3, 4};
47
48 BOOST_TEST_CONTEXT( "validating comparisons of a and b" )
49 validate_comparisons(a, b);
50 BOOST_TEST_CONTEXT( "validating comparisons of a and c" )
51 validate_comparisons(a, c);
52 BOOST_TEST_CONTEXT( "validating comparisons of a and d" )
53 validate_comparisons(a, d);
54 }
55
56 //____________________________________________________________________________//
57
58 BOOST_AUTO_TEST_CASE( test_per_element_eq, * ut::expected_failures(2) )
59 {
60 std::vector<int> a{1, 2, 3};
61 std::vector<int> b{1, 3, 2};
62
63 BOOST_TEST( a == b, tt::per_element() );
64 }
65
66 //____________________________________________________________________________//
67
68 BOOST_AUTO_TEST_CASE( test_per_element_ne, * ut::expected_failures(1) )
69 {
70 std::vector<int> a{1, 2, 3};
71 std::vector<int> b{1, 3, 2};
72
73 BOOST_TEST( a != b, tt::per_element() );
74 }
75
76 //____________________________________________________________________________//
77
78 BOOST_AUTO_TEST_CASE( test_per_element_lt, * ut::expected_failures(2) )
79 {
80 std::vector<int> a{1, 2, 3};
81 std::vector<int> b{1, 3, 2};
82
83 BOOST_TEST( a < b, tt::per_element() );
84 }
85
86 //____________________________________________________________________________//
87
88 BOOST_AUTO_TEST_CASE( test_per_element_ge, * ut::expected_failures(1) )
89 {
90 std::vector<int> a{1, 2, 3};
91 std::vector<int> b{1, 3, 2};
92
93 BOOST_TEST( b >= a, tt::per_element() );
94 }
95
96 //____________________________________________________________________________//
97
98 BOOST_AUTO_TEST_CASE( test_lexicographic_lt )
99 {
100 std::vector<int> a{1, 2, 3};
101 std::vector<int> b{1, 3, 2};
102
103 BOOST_TEST( a < b, tt::lexicographic() );
104 }
105
106 //____________________________________________________________________________//
107
108 BOOST_AUTO_TEST_CASE( test_lexicographic_le )
109 {
110 std::vector<int> a{1, 2, 3};
111 std::vector<int> b{1, 3, 2};
112
113 BOOST_TEST( a <= b, tt::lexicographic() );
114 }
115
116 //____________________________________________________________________________//
117
118 BOOST_AUTO_TEST_CASE( test_lexicographic_gt )
119 {
120 std::vector<int> a{1, 2, 3};
121 std::vector<int> b{1, 3, 2};
122
123 BOOST_TEST( b > a, tt::lexicographic() );
124 }
125
126 //____________________________________________________________________________//
127
128 BOOST_AUTO_TEST_CASE( test_lexicographic_ge )
129 {
130 std::vector<int> a{1, 2, 3};
131 std::vector<int> b{1, 3, 2};
132
133 BOOST_TEST( b >= a, tt::lexicographic() );
134 }
135
136 //____________________________________________________________________________//
137
138 BOOST_AUTO_TEST_CASE( test_collection_of_collection_comp )
139 {
140 BOOST_TEST( std::string("abc") == std::string("abc") );
141 }
142
143 // EOF