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)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// @brief tests collection comparison implementation
10 // ***************************************************************************
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
;
18 BOOST_TEST_SPECIALIZED_COLLECTION_COMPARE(std::vector
<int>)
20 #define VALIDATE_OP( op ) \
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 ); \
29 template<typename Col
>
31 validate_comparisons(Col
const& c1
, Col
const& c2
)
41 BOOST_AUTO_TEST_CASE( test_against_overloaded_comp_op
)
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};
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
);
56 //____________________________________________________________________________//
58 BOOST_AUTO_TEST_CASE( test_per_element_eq
, * ut::expected_failures(2) )
60 std::vector
<int> a
{1, 2, 3};
61 std::vector
<int> b
{1, 3, 2};
63 BOOST_TEST( a
== b
, tt::per_element() );
66 //____________________________________________________________________________//
68 BOOST_AUTO_TEST_CASE( test_per_element_ne
, * ut::expected_failures(1) )
70 std::vector
<int> a
{1, 2, 3};
71 std::vector
<int> b
{1, 3, 2};
73 BOOST_TEST( a
!= b
, tt::per_element() );
76 //____________________________________________________________________________//
78 BOOST_AUTO_TEST_CASE( test_per_element_lt
, * ut::expected_failures(2) )
80 std::vector
<int> a
{1, 2, 3};
81 std::vector
<int> b
{1, 3, 2};
83 BOOST_TEST( a
< b
, tt::per_element() );
86 //____________________________________________________________________________//
88 BOOST_AUTO_TEST_CASE( test_per_element_ge
, * ut::expected_failures(1) )
90 std::vector
<int> a
{1, 2, 3};
91 std::vector
<int> b
{1, 3, 2};
93 BOOST_TEST( b
>= a
, tt::per_element() );
96 //____________________________________________________________________________//
98 BOOST_AUTO_TEST_CASE( test_lexicographic_lt
)
100 std::vector
<int> a
{1, 2, 3};
101 std::vector
<int> b
{1, 3, 2};
103 BOOST_TEST( a
< b
, tt::lexicographic() );
106 //____________________________________________________________________________//
108 BOOST_AUTO_TEST_CASE( test_lexicographic_le
)
110 std::vector
<int> a
{1, 2, 3};
111 std::vector
<int> b
{1, 3, 2};
113 BOOST_TEST( a
<= b
, tt::lexicographic() );
116 //____________________________________________________________________________//
118 BOOST_AUTO_TEST_CASE( test_lexicographic_gt
)
120 std::vector
<int> a
{1, 2, 3};
121 std::vector
<int> b
{1, 3, 2};
123 BOOST_TEST( b
> a
, tt::lexicographic() );
126 //____________________________________________________________________________//
128 BOOST_AUTO_TEST_CASE( test_lexicographic_ge
)
130 std::vector
<int> a
{1, 2, 3};
131 std::vector
<int> b
{1, 3, 2};
133 BOOST_TEST( b
>= a
, tt::lexicographic() );
136 //____________________________________________________________________________//
138 BOOST_AUTO_TEST_CASE( test_collection_of_collection_comp
)
140 BOOST_TEST( std::string("abc") == std::string("abc") );