// // libsemigroups - C++ library for semigroups and monoids // Copyright (C) 2019 James D. Mitchell // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
// The purpose of this file is to test the CongruenceInterface class.
#define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
#include <cstddef>
#include"catch.hpp"// for REQUIRE, SECTION, ... #include"test-main.hpp"// for LIBSEMIGROUPS_TEST_CASE
#include"libsemigroups/cong-pair.hpp"// for FpSemigroupByPairs #include"libsemigroups/fpsemi-intf.hpp"// for FpSemigroupInterface #include"libsemigroups/fpsemi.hpp"// for FpSemigroup #include"libsemigroups/knuth-bendix.hpp"// for fpsemigroup::KnuthBendix #include"libsemigroups/order.hpp"// for shortlex_words #include"libsemigroups/string.hpp"// for to_string of rule_type for debugging #include"libsemigroups/todd-coxeter.hpp"// for fpsemigroup::ToddCoxeter #include"libsemigroups/transf.hpp"// for fpsemigroup::ToddCoxeter #include"libsemigroups/wislo.hpp"// for cbegin_wislo #include"libsemigroups/word.hpp"// for number_of_words
// Too many
REQUIRE_THROWS_AS(fp->set_alphabet(300), LibsemigroupsException);
fp->set_alphabet("ab"); // Set more than once
REQUIRE_THROWS_AS(fp->set_alphabet("ab"), LibsemigroupsException);
REQUIRE_THROWS_AS(fp->set_alphabet(2), LibsemigroupsException);
}
// Too many
REQUIRE_THROWS_AS(fp->set_alphabet(300), LibsemigroupsException);
// Set more than once
REQUIRE_THROWS_AS(fp->set_alphabet("ab"), LibsemigroupsException);
REQUIRE_THROWS_AS(fp->set_alphabet(2), LibsemigroupsException);
}
LIBSEMIGROUPS_TEST_CASE("FpSemigroupInterface", "005", "add_rule after finished", "[quick]") { auto rg = ReportGuard(REPORT);
LIBSEMIGROUPS_TEST_CASE("FpSemigroupInterface", "012", "add_rules (2/3)", "[quick]") { auto rg = ReportGuard(REPORT);
using Transf = LeastTransf<5>;
FroidurePin<Transf> S({Transf({1, 3, 4, 2, 3}), Transf({3, 2, 1, 3, 3})});
FpSemigroupByPairs<decltype(S)> fp(S);
REQUIRE(fp.number_of_rules() == 18);
REQUIRE(fp.congruence().number_of_generating_pairs() == 0); // Generating pairs are the extra generating pairs added, whereas // the number_of_rules is the number of rules of defining the semigroup // over which the congruence is defined.
REQUIRE(fp.congruence().number_of_generating_pairs() == 0);
// No alphabet
REQUIRE_THROWS_AS(fp->set_identity("a"), LibsemigroupsException); // Too long
REQUIRE_THROWS_AS(fp->set_identity("aa"), LibsemigroupsException);
REQUIRE_NOTHROW(fp->set_alphabet("ab"));
// Letter out of range
REQUIRE_THROWS_AS(fp->set_identity("x"), LibsemigroupsException); // Too long
REQUIRE_THROWS_AS(fp->set_identity("aa"), LibsemigroupsException);
auto a = std::string(1, fp->alphabet()[0]); auto b = std::string(1, fp->alphabet()[1]);
REQUIRE_NOTHROW(fp->set_identity(0));
REQUIRE(fp->identity() == a);
// Letter out of range
REQUIRE_THROWS_AS(fp->set_identity(letter_type(10)),
LibsemigroupsException);
REQUIRE(fp->identity() == a);
REQUIRE(std::vector<rule_type>(fp->cbegin_rules(), fp->cend_rules())
== std::vector<rule_type>(
{rule_type({b + b + b, b}),
rule_type({b + b + a + b, b + a + b}),
rule_type({a + a + a + a + a, a + a}),
rule_type({a + b + a + a + b, a + a + a + a + b}),
rule_type({b + a + a + a + a, b + a}),
rule_type({b + b + a + a + b, b + a + a + a + b}),
rule_type({a + a + b + a + b + a, a + a + b + b}),
rule_type({a + a + b + a + b + b, a + a + b + a}),
rule_type({b + a + b + a + b + a, b + a + b + b}),
rule_type({b + a + b + a + b + b, b + a + b + a}),
rule_type({b + b + a + a + a + b, b + a + a + b}),
rule_type({a + a + b + b + a + a + a, a + a + b + b}),
rule_type(
{b + a + b + a + a + a + b, a + a + b + a + a + a + b}),
rule_type({b + a + b + b + a + a + a, b + a + b + b}),
rule_type({a + a + a + b + a + a + a + b,
a + a + b + a + a + a + b}),
rule_type({a + a + b + a + a + a + b + b,
a + a + b + a + a + a + b}),
rule_type({b + a + a + b + a + a + a + b,
a + a + b + a + a + a + b}),
rule_type({a + a + b + a + a + a + b + a + a + a,
a + a + b + a + a + a + b}),
rule_type({a + a, a}),
rule_type({b + a, b}),
rule_type({a + b, b})}));
}
LIBSEMIGROUPS_TEST_CASE("FpSemigroupInterface", "018", "set_inverses + inverses (1/2)", "[quick]") { using rule_type = typename FpSemigroupInterface::rule_type; auto rg = ReportGuard(REPORT);
std::unique_ptr<FpSemigroupInterface> fp;
SECTION("ToddCoxeter") {
fp = std::make_unique<ToddCoxeter>();
}
SECTION("KnuthBendix") {
fp = std::make_unique<KnuthBendix>();
}
SECTION("FpSemigroup") {
fp = std::make_unique<FpSemigroup>();
} // No alphabet
REQUIRE_THROWS_AS(fp->set_inverses("bac"), LibsemigroupsException); // Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException);
// No identity
fp->set_alphabet("abc");
REQUIRE_THROWS_AS(fp->set_inverses("bac"), LibsemigroupsException); // Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException);
fp->set_identity("c"); // Duplicates
REQUIRE_THROWS_AS(fp->set_inverses("bbc"), LibsemigroupsException); // Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException); // Wrong size
REQUIRE_THROWS_AS(fp->set_inverses("bc"), LibsemigroupsException); // Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException);
fp->set_inverses("bac"); // Can't set inverses more than once
REQUIRE_THROWS_AS(fp->set_inverses("abc"), LibsemigroupsException);
REQUIRE(std::vector<rule_type>(fp->cbegin_rules(), fp->cend_rules())
== std::vector<rule_type>({{"ac", "a"},
{"ca", "a"},
{"bc", "b"},
{"cb", "b"},
{"cc", "c"},
{"ab", "c"},
{"ba", "c"}}));
REQUIRE(fp->inverses() == "bac");
}
auto a = std::string(1, fp->alphabet()[0]); auto b = std::string(1, fp->alphabet()[1]);
// Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException);
// No identity
REQUIRE_THROWS_AS(fp->set_inverses(b + a), LibsemigroupsException); // Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException);
fp->set_identity(a); // Duplicates
REQUIRE_THROWS_AS(fp->set_inverses(b + b), LibsemigroupsException); // Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException); // Wrong size
REQUIRE_THROWS_AS(fp->set_inverses(a), LibsemigroupsException); // Not set
REQUIRE_THROWS_AS(fp->inverses(), LibsemigroupsException);
// Inverse of the identity isn't the identity
REQUIRE_THROWS_AS(fp->set_inverses(b + a), LibsemigroupsException);
fp->set_inverses(a + b);
// Can't set inverses more than once
REQUIRE_THROWS_AS(fp->set_inverses(b + a), LibsemigroupsException);
// REQUIRE(std::vector<rule_type>(fp->cbegin_rules(), fp->cend_rules()) // == std::vector<rule_type>( // {rule_type({b + b + b, b}), // rule_type({b + b + a + b, b + a + b}), // rule_type({a + a + a + a + a, a + a}), // rule_type({a + b + a + a + b, a + a + a + a + b}), // rule_type({b + a + a + a + a, b + a}), // rule_type({b + b + a + a + b, b + a + a + a + b}), // rule_type({a + a + b + a + b + a, a + a + b + b}), // rule_type({a + a + b + a + b + b, a + a + b + a}), // rule_type({b + a + b + a + b + a, b + a + b + b}), // rule_type({b + a + b + a + b + b, b + a + b + a}), // rule_type({b + b + a + a + a + b, b + a + a + b}), // rule_type({a + a + b + b + a + a + a, a + a + b + b}), // rule_type( // {b + a + b + a + a + a + b, a + a + b + a + a + a + // b}), // rule_type({b + a + b + b + a + a + a, b + a + b + b}), // rule_type({a + a + a + b + a + a + a + b, // a + a + b + a + a + a + b}), // rule_type({a + a + b + a + a + a + b + b, // a + a + b + a + a + a + b}), // rule_type({b + a + a + b + a + a + a + b, // a + a + b + a + a + a + b}), // rule_type({a + a + b + a + a + a + b + a + a + a, // a + a + b + a + a + a + b}), // rule_type({a + a, a}), // rule_type({b + a, b}), // rule_type({a + b, b}), // rule_type({a + b, a}), // rule_type({b + a, a})}));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.