• 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_SCANS_HPP
6 #define BOOST_HANA_TEST_AUTO_SCANS_HPP
7 
8 #include <boost/hana/assert.hpp>
9 #include <boost/hana/equal.hpp>
10 #include <boost/hana/scan_left.hpp>
11 #include <boost/hana/scan_right.hpp>
12 
13 #include <laws/base.hpp>
14 #include "test_case.hpp"
15 
16 
__anon8761242f0102null17 TestCase test_scan_left{[]{
18     namespace hana = boost::hana;
19     using hana::test::ct_eq;
20 
21     struct undefined { };
22     hana::test::_injection<0> f{};
23 
24     // Without initial state
25     BOOST_HANA_CONSTANT_CHECK(hana::equal(
26         hana::scan_left(MAKE_TUPLE(), undefined{}),
27         MAKE_TUPLE()
28     ));
29     BOOST_HANA_CONSTANT_CHECK(hana::equal(
30         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}), undefined{}),
31         MAKE_TUPLE(ct_eq<0>{})
32     ));
33     BOOST_HANA_CONSTANT_CHECK(hana::equal(
34         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), f),
35         MAKE_TUPLE(ct_eq<0>{}, f(ct_eq<0>{}, ct_eq<1>{}))
36     ));
37     BOOST_HANA_CONSTANT_CHECK(hana::equal(
38         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), f),
39         MAKE_TUPLE(
40             ct_eq<0>{},
41             f(ct_eq<0>{}, ct_eq<1>{}),
42             f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{})
43         )
44     ));
45     BOOST_HANA_CONSTANT_CHECK(hana::equal(
46         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), f),
47         MAKE_TUPLE(
48             ct_eq<0>{},
49             f(ct_eq<0>{}, ct_eq<1>{}),
50             f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}),
51             f(f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{})
52         )
53     ));
54     BOOST_HANA_CONSTANT_CHECK(hana::equal(
55         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), f),
56         MAKE_TUPLE(
57             ct_eq<0>{},
58             f(ct_eq<0>{}, ct_eq<1>{}),
59             f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}),
60             f(f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}),
61             f(f(f(f(ct_eq<0>{}, ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}), ct_eq<4>{})
62         )
63     ));
64 
65     // With initial state
66     auto s = ct_eq<999>{};
67     BOOST_HANA_CONSTANT_CHECK(hana::equal(
68         hana::scan_left(MAKE_TUPLE(), s, undefined{}),
69         MAKE_TUPLE(s)
70     ));
71     BOOST_HANA_CONSTANT_CHECK(hana::equal(
72         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}), s, f),
73         MAKE_TUPLE(s, f(s, ct_eq<0>{}))
74     ));
75     BOOST_HANA_CONSTANT_CHECK(hana::equal(
76         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), s, f),
77         MAKE_TUPLE(s, f(s, ct_eq<0>{}), f(f(s, ct_eq<0>{}), ct_eq<1>{}))
78     ));
79     BOOST_HANA_CONSTANT_CHECK(hana::equal(
80         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), s, f),
81         MAKE_TUPLE(
82             s,
83             f(s, ct_eq<0>{}),
84             f(f(s, ct_eq<0>{}), ct_eq<1>{}),
85             f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{})
86         )
87     ));
88     BOOST_HANA_CONSTANT_CHECK(hana::equal(
89         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), s, f),
90         MAKE_TUPLE(
91             s,
92             f(s, ct_eq<0>{}),
93             f(f(s, ct_eq<0>{}), ct_eq<1>{}),
94             f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}),
95             f(f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{})
96         )
97     ));
98     BOOST_HANA_CONSTANT_CHECK(hana::equal(
99         hana::scan_left(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), s, f),
100         MAKE_TUPLE(
101             s,
102             f(s, ct_eq<0>{}),
103             f(f(s, ct_eq<0>{}), ct_eq<1>{}),
104             f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}),
105             f(f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}),
106             f(f(f(f(f(s, ct_eq<0>{}), ct_eq<1>{}), ct_eq<2>{}), ct_eq<3>{}), ct_eq<4>{})
107         )
108     ));
109 }};
110 
111 
__anon8761242f0202null112 TestCase test_scan_right{[]{
113     namespace hana = boost::hana;
114     using hana::test::ct_eq;
115 
116     struct undefined { };
117     hana::test::_injection<0> f{};
118 
119     // Without initial state
120     BOOST_HANA_CONSTANT_CHECK(hana::equal(
121         hana::scan_right(MAKE_TUPLE(), undefined{}),
122         MAKE_TUPLE()
123     ));
124     BOOST_HANA_CONSTANT_CHECK(hana::equal(
125         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}), undefined{}),
126         MAKE_TUPLE(ct_eq<0>{})
127     ));
128     BOOST_HANA_CONSTANT_CHECK(hana::equal(
129         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), f),
130         MAKE_TUPLE(
131             f(ct_eq<0>{}, ct_eq<1>{}),
132                           ct_eq<1>{}
133         )
134     ));
135     BOOST_HANA_CONSTANT_CHECK(hana::equal(
136         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), f),
137         MAKE_TUPLE(
138             f(ct_eq<0>{}, f(ct_eq<1>{}, ct_eq<2>{})),
139                           f(ct_eq<1>{}, ct_eq<2>{}),
140                                         ct_eq<2>{}
141         )
142     ));
143     BOOST_HANA_CONSTANT_CHECK(hana::equal(
144         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), f),
145         MAKE_TUPLE(
146             f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, ct_eq<3>{}))),
147                           f(ct_eq<1>{}, f(ct_eq<2>{}, ct_eq<3>{})),
148                                         f(ct_eq<2>{}, ct_eq<3>{}),
149                                                       ct_eq<3>{}
150         )
151     ));
152     BOOST_HANA_CONSTANT_CHECK(hana::equal(
153         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), f),
154         MAKE_TUPLE(
155             f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, ct_eq<4>{})))),
156                           f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, ct_eq<4>{}))),
157                                         f(ct_eq<2>{}, f(ct_eq<3>{}, ct_eq<4>{})),
158                                                       f(ct_eq<3>{}, ct_eq<4>{}),
159                                                                     ct_eq<4>{}
160         )
161     ));
162 
163     // With initial state
164     auto s = ct_eq<999>{};
165     BOOST_HANA_CONSTANT_CHECK(hana::equal(
166         hana::scan_right(MAKE_TUPLE(), s, undefined{}),
167         MAKE_TUPLE(s)
168     ));
169     BOOST_HANA_CONSTANT_CHECK(hana::equal(
170         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}), s, f),
171         MAKE_TUPLE(
172             f(ct_eq<0>{}, s),
173             s
174         )
175     ));
176     BOOST_HANA_CONSTANT_CHECK(hana::equal(
177         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}), s, f),
178         MAKE_TUPLE(
179             f(ct_eq<0>{}, f(ct_eq<1>{}, s)),
180                           f(ct_eq<1>{}, s),
181                                         s
182         )
183     ));
184     BOOST_HANA_CONSTANT_CHECK(hana::equal(
185         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}), s, f),
186         MAKE_TUPLE(
187             f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, s))),
188                           f(ct_eq<1>{}, f(ct_eq<2>{}, s)),
189                                         f(ct_eq<2>{}, s),
190                                                       s
191         )
192     ));
193     BOOST_HANA_CONSTANT_CHECK(hana::equal(
194         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), s, f),
195         MAKE_TUPLE(
196             f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, s)))),
197                           f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, s))),
198                                         f(ct_eq<2>{}, f(ct_eq<3>{}, s)),
199                                                       f(ct_eq<3>{}, s),
200                                                                     s
201         )
202     ));
203     BOOST_HANA_CONSTANT_CHECK(hana::equal(
204         hana::scan_right(MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}), s, f),
205         MAKE_TUPLE(
206             f(ct_eq<0>{}, f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, f(ct_eq<4>{}, s))))),
207                           f(ct_eq<1>{}, f(ct_eq<2>{}, f(ct_eq<3>{}, f(ct_eq<4>{}, s)))),
208                                         f(ct_eq<2>{}, f(ct_eq<3>{}, f(ct_eq<4>{}, s))),
209                                                       f(ct_eq<3>{}, f(ct_eq<4>{}, s)),
210                                                                     f(ct_eq<4>{}, s),
211                                                                                   s
212         )
213     ));
214 }};
215 
216 #endif // !BOOST_HANA_TEST_AUTO_SCANS_HPP
217