1 // Copyright Louis Dionne 2013-2016
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)
5 #ifndef BOOST_HANA_TEST_LAWS_GROUP_HPP
6 #define BOOST_HANA_TEST_LAWS_GROUP_HPP
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>
15 #include <laws/base.hpp>
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;
25 struct TestGroup<G, laws> {
26 template <typename Xs>
28 hana::for_each(xs, [](auto x) {
29 static_assert(Group<decltype(x)>::value, "");
32 foreach2(xs, [](auto x, auto y) {
35 BOOST_HANA_CHECK(hana::equal(
36 hana::plus(x, hana::negate(x)),
41 BOOST_HANA_CHECK(hana::equal(
42 hana::plus(hana::negate(x), x),
46 // default definition of minus
47 BOOST_HANA_CHECK(hana::equal(
49 hana::plus(x, hana::negate(y))
52 BOOST_HANA_CHECK(hana::equal(
54 hana::plus(y, hana::negate(x))
57 // default definition of negate
58 BOOST_HANA_CHECK(hana::equal(
59 hana::negate(hana::negate(x)),
67 struct TestGroup<C, when<Constant<C>::value>>
70 template <typename Xs>
71 TestGroup(Xs xs) : TestGroup<C, laws>{xs} {
72 foreach2(xs, [](auto x, auto y) {
74 BOOST_HANA_CHECK(hana::equal(
75 hana::negate(hana::value(x)),
76 hana::value(hana::negate(x))
79 BOOST_HANA_CHECK(hana::equal(
80 hana::minus(hana::value(x), hana::value(y)),
81 hana::value(hana::minus(x, y))
87 }}} // end namespace boost::hana::test
89 #endif // !BOOST_HANA_TEST_LAWS_GROUP_HPP