• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4 
5 #ifndef BOOST_HANA_TEST_AUTO_UNIQUE_HPP
6 #define BOOST_HANA_TEST_AUTO_UNIQUE_HPP
7 
8 #include <boost/hana/assert.hpp>
9 #include <boost/hana/equal.hpp>
10 #include <boost/hana/unique.hpp>
11 
12 #include "test_case.hpp"
13 #include <laws/base.hpp>
14 #include <support/equivalence_class.hpp>
15 
16 
__anoneb61c2900102null17 TestCase test_unique{[]{
18     namespace hana = boost::hana;
19     using hana::test::ct_eq;
20 
21     BOOST_HANA_CONSTANT_CHECK(hana::equal(
22         hana::unique(MAKE_TUPLE()),
23         MAKE_TUPLE()
24     ));
25 
26     BOOST_HANA_CONSTANT_CHECK(hana::equal(
27         hana::unique(MAKE_TUPLE(ct_eq<0>{})),
28         MAKE_TUPLE(ct_eq<0>{})
29     ));
30 
31     BOOST_HANA_CONSTANT_CHECK(hana::equal(
32         hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{})),
33         MAKE_TUPLE(ct_eq<0>{})
34     ));
35     BOOST_HANA_CONSTANT_CHECK(hana::equal(
36         hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})),
37         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})
38     ));
39 
40     BOOST_HANA_CONSTANT_CHECK(hana::equal(
41         hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{})),
42         MAKE_TUPLE(ct_eq<0>{})
43     ));
44     BOOST_HANA_CONSTANT_CHECK(hana::equal(
45         hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<1>{})),
46         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})
47     ));
48     BOOST_HANA_CONSTANT_CHECK(hana::equal(
49         hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<0>{})),
50         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<0>{})
51     ));
52     BOOST_HANA_CONSTANT_CHECK(hana::equal(
53         hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<1>{})),
54         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{})
55     ));
56     BOOST_HANA_CONSTANT_CHECK(hana::equal(
57         hana::unique(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})),
58         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
59     ));
60 
61     BOOST_HANA_CONSTANT_CHECK(hana::equal(
62         hana::unique(MAKE_TUPLE(
63             ct_eq<0>{}, ct_eq<0>{},
64             ct_eq<1>{},
65             ct_eq<2>{}, ct_eq<2>{}, ct_eq<2>{},
66             ct_eq<3>{}, ct_eq<3>{}, ct_eq<3>{},
67             ct_eq<0>{})),
68         MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<0>{})
69     ));
70 }};
71 
__anoneb61c2900202null72 TestCase test_unique_by{[]{
73     namespace hana = boost::hana;
74     using hana::test::ct_eq;
75 
76     struct undefined { };
77 
78     auto a = [](auto z) { return ::equivalence_class(ct_eq<999>{}, z); };
79     auto b = [](auto z) { return ::equivalence_class(ct_eq<888>{}, z); };
80     auto c = [](auto z) { return ::equivalence_class(ct_eq<777>{}, z); };
81 
82     auto pred = [](auto x, auto y) {
83         return hana::equal(x.unwrap, y.unwrap);
84     };
85 
86     BOOST_HANA_CONSTANT_CHECK(hana::equal(
87         hana::unique(MAKE_TUPLE(), undefined{}),
88         MAKE_TUPLE()
89     ));
90 
91     BOOST_HANA_CONSTANT_CHECK(hana::equal(
92         hana::unique(MAKE_TUPLE(a(ct_eq<0>{})), pred),
93         MAKE_TUPLE(a(ct_eq<0>{}))
94     ));
95 
96     BOOST_HANA_CONSTANT_CHECK(hana::equal(
97         hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{})), pred),
98         MAKE_TUPLE(a(ct_eq<0>{}))
99     ));
100     BOOST_HANA_CONSTANT_CHECK(hana::equal(
101         hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{})), pred),
102         MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}))
103     ));
104 
105     BOOST_HANA_CONSTANT_CHECK(hana::equal(
106         hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), c(ct_eq<0>{})), pred),
107         MAKE_TUPLE(a(ct_eq<0>{}))
108     ));
109     BOOST_HANA_CONSTANT_CHECK(hana::equal(
110         hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<0>{}), c(ct_eq<1>{})), pred),
111         MAKE_TUPLE(a(ct_eq<0>{}), c(ct_eq<1>{}))
112     ));
113     BOOST_HANA_CONSTANT_CHECK(hana::equal(
114         hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<0>{})), pred),
115         MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<0>{}))
116     ));
117     BOOST_HANA_CONSTANT_CHECK(hana::equal(
118         hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<1>{}), b(ct_eq<1>{})), pred),
119         MAKE_TUPLE(a(ct_eq<0>{}), b(ct_eq<1>{}))
120     ));
121     BOOST_HANA_CONSTANT_CHECK(hana::equal(
122         hana::unique(MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{})), pred),
123         MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{}))
124     ));
125 
126     BOOST_HANA_CONSTANT_CHECK(hana::equal(
127         hana::unique(MAKE_TUPLE(
128             a(ct_eq<0>{}), b(ct_eq<0>{}),
129             a(ct_eq<1>{}),
130             a(ct_eq<2>{}), b(ct_eq<2>{}), c(ct_eq<2>{}),
131             a(ct_eq<3>{}), b(ct_eq<3>{}), c(ct_eq<3>{}),
132             a(ct_eq<0>{})), pred),
133         MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{}), a(ct_eq<3>{}), a(ct_eq<0>{}))
134     ));
135 
136     // unique.by
137     BOOST_HANA_CONSTANT_CHECK(hana::equal(
138         hana::unique.by(pred, MAKE_TUPLE(
139             a(ct_eq<0>{}), b(ct_eq<0>{}),
140             a(ct_eq<1>{}),
141             a(ct_eq<2>{}), b(ct_eq<2>{}), c(ct_eq<2>{}),
142             a(ct_eq<3>{}), b(ct_eq<3>{}), c(ct_eq<3>{}),
143             a(ct_eq<0>{}))),
144         MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{}), a(ct_eq<3>{}), a(ct_eq<0>{}))
145     ));
146 
147     BOOST_HANA_CONSTANT_CHECK(hana::equal(
148         hana::unique.by(pred)(MAKE_TUPLE(
149             a(ct_eq<0>{}), b(ct_eq<0>{}),
150             a(ct_eq<1>{}),
151             a(ct_eq<2>{}), b(ct_eq<2>{}), c(ct_eq<2>{}),
152             a(ct_eq<3>{}), b(ct_eq<3>{}), c(ct_eq<3>{}),
153             a(ct_eq<0>{}))),
154         MAKE_TUPLE(a(ct_eq<0>{}), a(ct_eq<1>{}), a(ct_eq<2>{}), a(ct_eq<3>{}), a(ct_eq<0>{}))
155     ));
156 }};
157 
158 #endif // !BOOST_HANA_TEST_AUTO_UNIQUE_HPP
159