1 //
2 // libsemigroups - C++ library for semigroups and monoids
3 // Copyright (C) 2019 James D. Mitchell
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <cstddef>      // for size_t
20 #include <cstdint>      // for uint8_t
21 #include <type_traits>  // for enable_if, is_integral
22 
23 #include "adapters.hpp"             // for complexity etc
24 #include "catch.hpp"                // for LIBSEMIGROUPS_TEST_CASE
25 #include "froidure-pin.hpp"         // for FroidurePin<>::element_i...
26 #include "libsemigroups-debug.hpp"  // for LIBSEMIGROUPS_ASSERT
27 #include "test-main.hpp"
28 
29 namespace libsemigroups {
30 
31   constexpr bool REPORT = false;
32 
33   template <typename TIntegralType>
34   struct Complexity<
35       TIntegralType,
36       typename std::enable_if<std::is_integral<TIntegralType>::value>::type> {
operator ()libsemigroups::Complexity37     constexpr size_t operator()(TIntegralType) const noexcept {
38       return 0;
39     }
40   };
41 
42   template <typename TIntegralType>
43   struct Degree<
44       TIntegralType,
45       typename std::enable_if<std::is_integral<TIntegralType>::value>::type> {
operator ()libsemigroups::Degree46     constexpr size_t operator()(TIntegralType) const noexcept {
47       return 0;
48     }
49   };
50 
51   template <typename TIntegralType>
52   struct IncreaseDegree<
53       TIntegralType,
54       typename std::enable_if<std::is_integral<TIntegralType>::value>::type> {
operator ()libsemigroups::IncreaseDegree55     TIntegralType operator()(TIntegralType x) const noexcept {
56       LIBSEMIGROUPS_ASSERT(false);
57       return x;
58     }
59   };
60 
61   template <typename TIntegralType>
62   struct One<
63       TIntegralType,
64       typename std::enable_if<std::is_integral<TIntegralType>::value>::type> {
operator ()libsemigroups::One65     constexpr TIntegralType operator()(TIntegralType) const noexcept {
66       return 1;
67     }
68   };
69 
70   template <typename TIntegralType>
71   struct Product<
72       TIntegralType,
73       typename std::enable_if<std::is_integral<TIntegralType>::value>::type> {
operator ()libsemigroups::Product74     void operator()(TIntegralType& xy,
75                     TIntegralType  x,
76                     TIntegralType  y,
77                     size_t = 0) const noexcept {
78       xy = x * y;
79     }
80   };
81 
82   // #ifdef LIBSEMIGROUPS_DENSEHASHMAP
83   //   template <typename TIntegralType>
84   //   struct EmptyKey<
85   //       TIntegralType,
86   //       typename
87   //       std::enable_if<std::is_integral<TIntegralType>::value>::type> {
88   //     TIntegralType operator()(TIntegralType) const noexcept {
89   //       return UNDEFINED;
90   //     }
91   //   }
92   // #endif
93 
94   LIBSEMIGROUPS_TEST_CASE("FroidurePin",
95                           "102",
96                           "(integers)",
97                           "[quick][froidure-pin][integers]") {
98     auto             rg = ReportGuard(REPORT);
99     FroidurePin<int> S({2});
100     REQUIRE(S.size() == 32);
101     REQUIRE(S.nr_idempotents() == 1);
102     FroidurePin<int>::const_iterator it = S.cbegin();
103     REQUIRE(*it == 2);
104 
105     FroidurePin<uint8_t> T({2, 3});
106     REQUIRE(T.size() == 130);
107     REQUIRE(T.nr_idempotents() == 2);
108     REQUIRE(*T.cbegin_idempotents() == 0);
109     REQUIRE(*T.cbegin_idempotents() + 1 == 1);
110   }
111 }  // namespace libsemigroups
112