summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/poly_collection/test/test_comparison.cpp
blob: 8a767902b77e417cd8df278302c3102db121dc92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Copyright 2016-2018 Joaquin M Lopez Munoz.
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 *
 * See http://www.boost.org/libs/poly_collection for library home page.
 */

#include "test_comparison.hpp"

#include <boost/core/lightweight_test.hpp>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"

using namespace test_utilities;

template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_comparison()
{
  {
    PolyCollection        p1,p2;
    const PolyCollection& cp1=p1;
    const PolyCollection& cp2=p2;

    BOOST_TEST(cp1==cp1);
    BOOST_TEST(!(cp1!=cp1));
    BOOST_TEST(cp1==cp2);
    BOOST_TEST(!(cp1!=cp2));
  }
  {
    PolyCollection        p1,p2;
    const PolyCollection& cp1=p1;
    const PolyCollection& cp2=p2;
    ValueFactory          v;

    fill<
      constraints<is_not_equality_comparable>,
      Types...
    >(p1,v,2);

    BOOST_TEST(!(cp1==cp2));
    BOOST_TEST(cp1!=cp2);
  }
  {
    PolyCollection        p1,p2;
    const PolyCollection& cp1=p1;
    const PolyCollection& cp2=p2;
    ValueFactory          v;

    p1.template register_types<Types...>();
    fill<
      constraints<is_not_equality_comparable>,
      Types...
    >(p1,v,2);

    BOOST_TEST(!(cp1==cp2));
    BOOST_TEST(cp1!=cp2);
  }
  {
    PolyCollection        p1,p2;
    const PolyCollection& cp1=p1;
    const PolyCollection& cp2=p2;
    ValueFactory          v;

    fill<
      constraints<is_not_equality_comparable>,
      Types...
    >(p1,v,1);
    fill<
      constraints<is_not_equality_comparable>,
      Types...
    >(p2,v,2);

    BOOST_TEST(!(cp1==cp2));
    BOOST_TEST(cp1!=cp2);
  }
  {
    using not_equality_comparable=
      boost::poly_collection::not_equality_comparable;

    PolyCollection        p1,p2;
    const PolyCollection& cp1=p1;
    const PolyCollection& cp2=p2;
    ValueFactory          v;

    fill<
      constraints<is_not_equality_comparable>,
      Types...
    >(p1,v,2);
    fill<
      constraints<is_not_equality_comparable>,
      Types...
    >(p2,v,2);

    check_throw<not_equality_comparable>(
     [&]{(void)(cp1==cp2);},
     [&]{(void)(cp1!=cp2);});
  }
  {
    PolyCollection        p1,p2;
    const PolyCollection& cp1=p1;
    const PolyCollection& cp2=p2;
    ValueFactory          v;

    fill<
      constraints<is_not_equality_comparable>,
      Types...
    >(p1,v,2);
    fill<
      constraints<is_equality_comparable,is_copy_constructible>,
      Types...
    >(p2,v,2);
    p1.insert(p2.begin(),p2.end());

    BOOST_TEST(!(cp1==cp2));
    BOOST_TEST(cp1!=cp2);
  }
  {
    PolyCollection        p1,p2;
    const PolyCollection& cp1=p1;
    const PolyCollection& cp2=p2;
    ValueFactory          v;

    p1.template register_types<Types...>();
    fill<
      constraints<is_equality_comparable,is_copy_constructible>,
      Types...
    >(p2,v,2);
    p1.insert(p2.begin(),p2.end());

    BOOST_TEST(cp1==cp2);
    BOOST_TEST(!(cp1!=cp2));

    p1.erase(p1.begin());
    BOOST_TEST(!(cp1==cp2));
    BOOST_TEST(cp1!=cp2);
  }
}

void test_stateless_lambda_comparability_check()
{
  /* https://svn.boost.org/trac10/ticket/13012 */

  {
    boost::function_collection<void()> c1,c2;
    c1.insert([]{});
    BOOST_TEST(c1!=c2);
  }
  {
    boost::function_collection<int(int)> c1,c2;
    c1.insert([](int){return 0;});
    BOOST_TEST(c1!=c2);
  }
}

void test_comparison()
{
  test_comparison<
    any_types::collection,auto_increment,
    any_types::t1,any_types::t2,any_types::t3,
    any_types::t4,any_types::t5>();
  test_comparison<
    base_types::collection,auto_increment,
    base_types::t1,base_types::t2,base_types::t3,
    base_types::t4,base_types::t5>();
  test_comparison<
    function_types::collection,auto_increment,
    function_types::t1,function_types::t2,function_types::t3,
    function_types::t4,function_types::t5>();
  test_stateless_lambda_comparability_check();
}