]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/lightweight_test_all_with_fail.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / core / test / lightweight_test_all_with_fail.cpp
1 //
2 // Negative est for BOOST_TEST_ALL_WITH
3 //
4 // Copyright (c) 2017 Bjorn Reese
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt
9 //
10
11 #include <cmath>
12 #include <functional>
13 #include <vector>
14 #include <boost/core/lightweight_test.hpp>
15
16 int fail_vector()
17 {
18 int test_cases = 0;
19
20 {
21 std::vector<int> x, y;
22 x.push_back( 1 );
23 BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
24 ++test_cases;
25 }
26
27 {
28 std::vector<int> x, y;
29 y.push_back( 1 );
30 BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
31 ++test_cases;
32 }
33
34 {
35 std::vector<int> x, y;
36 x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
37 y.push_back( 1 ); y.push_back( 2 ); y.push_back( 3 );
38 BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
39 ++test_cases;
40 }
41
42 {
43 std::vector<int> x, y;
44 x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 );
45 y.push_back( 1 ); y.push_back( 2 ); y.push_back( 3 ); y.push_back( 4 );
46 BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
47 ++test_cases;
48 }
49
50 {
51 std::vector<int> x, y;
52 x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
53 y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
54 BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
55 ++test_cases;
56 }
57
58 {
59 std::vector<int> x, y;
60 x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
61 y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
62 BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::less<int>() );
63 ++test_cases;
64 }
65
66 return test_cases;
67 }
68
69 template <typename T>
70 struct with_tolerance
71 {
72 with_tolerance(T tolerance) : tolerance(tolerance) {}
73 bool operator()(T lhs, T rhs)
74 {
75 return (std::abs(lhs - rhs) <= tolerance);
76 }
77
78 private:
79 T tolerance;
80 };
81
82 int fail_tolerance_predicate()
83 {
84 int test_cases = 0;
85
86 {
87 std::vector<double> x, y;
88 x.push_back( 1.0 ); x.push_back( 1.0 );
89 y.push_back( 1.0 - 1e-4 ); y.push_back( 1.0 + 1e-4 );
90 BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), with_tolerance<double>(1e-5) );
91 ++test_cases;
92 }
93
94 return test_cases;
95 }
96
97 int main()
98 {
99 int test_cases = 0;
100
101 test_cases += fail_vector();
102 test_cases += fail_tolerance_predicate();
103
104 return boost::report_errors() == test_cases;
105 }