]>
Commit | Line | Data |
---|---|---|
b32b8144 | 1 | // Copyright Louis Dionne 2013-2017 |
7c673cae FG |
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_LAWS_GROUP_HPP | |
6 | #define BOOST_HANA_TEST_LAWS_GROUP_HPP | |
7 | ||
8 | #include <boost/hana/assert.hpp> | |
9 | #include <boost/hana/bool.hpp> | |
10 | #include <boost/hana/concept/comparable.hpp> | |
11 | #include <boost/hana/core/when.hpp> | |
12 | #include <boost/hana/concept/group.hpp> | |
13 | #include <boost/hana/lazy.hpp> | |
14 | ||
15 | #include <laws/base.hpp> | |
16 | ||
17 | ||
18 | namespace boost { namespace hana { namespace test { | |
19 | template <typename G, typename = when<true>> | |
20 | struct TestGroup : TestGroup<G, laws> { | |
21 | using TestGroup<G, laws>::TestGroup; | |
22 | }; | |
23 | ||
24 | template <typename G> | |
25 | struct TestGroup<G, laws> { | |
26 | template <typename Xs> | |
27 | TestGroup(Xs xs) { | |
28 | hana::for_each(xs, [](auto x) { | |
b32b8144 | 29 | static_assert(Group<decltype(x)>{}, ""); |
7c673cae FG |
30 | }); |
31 | ||
32 | foreach2(xs, [](auto x, auto y) { | |
33 | ||
34 | // left inverse | |
35 | BOOST_HANA_CHECK(hana::equal( | |
36 | hana::plus(x, hana::negate(x)), | |
37 | zero<G>() | |
38 | )); | |
39 | ||
40 | // right inverse | |
41 | BOOST_HANA_CHECK(hana::equal( | |
42 | hana::plus(hana::negate(x), x), | |
43 | zero<G>() | |
44 | )); | |
45 | ||
46 | // default definition of minus | |
47 | BOOST_HANA_CHECK(hana::equal( | |
48 | hana::minus(x, y), | |
49 | hana::plus(x, hana::negate(y)) | |
50 | )); | |
51 | ||
52 | BOOST_HANA_CHECK(hana::equal( | |
53 | hana::minus(y, x), | |
54 | hana::plus(y, hana::negate(x)) | |
55 | )); | |
56 | ||
57 | // default definition of negate | |
58 | BOOST_HANA_CHECK(hana::equal( | |
59 | hana::negate(hana::negate(x)), | |
60 | x | |
61 | )); | |
62 | }); | |
63 | } | |
64 | }; | |
65 | ||
66 | template <typename C> | |
67 | struct TestGroup<C, when<Constant<C>::value>> | |
68 | : TestGroup<C, laws> | |
69 | { | |
70 | template <typename Xs> | |
71 | TestGroup(Xs xs) : TestGroup<C, laws>{xs} { | |
72 | foreach2(xs, [](auto x, auto y) { | |
73 | ||
74 | BOOST_HANA_CHECK(hana::equal( | |
75 | hana::negate(hana::value(x)), | |
76 | hana::value(hana::negate(x)) | |
77 | )); | |
78 | ||
79 | BOOST_HANA_CHECK(hana::equal( | |
80 | hana::minus(hana::value(x), hana::value(y)), | |
81 | hana::value(hana::minus(x, y)) | |
82 | )); | |
83 | ||
84 | }); | |
85 | } | |
86 | }; | |
87 | }}} // end namespace boost::hana::test | |
88 | ||
89 | #endif // !BOOST_HANA_TEST_LAWS_GROUP_HPP |