From 0041f2263c34b6ab76155493b076cdb30061461c Mon Sep 17 00:00:00 2001 From: reiniscirpons Date: Wed, 1 May 2024 16:29:24 +0100 Subject: [PATCH] Add more coverage tests for Sims --- tests/test-sims.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/test-sims.cpp b/tests/test-sims.cpp index a09dcd815..4a36da7f8 100644 --- a/tests/test-sims.cpp +++ b/tests/test-sims.cpp @@ -18,6 +18,7 @@ #include "libsemigroups/detail/stl.hpp" #include "libsemigroups/word-graph.hpp" +#include #define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER #define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER @@ -4006,6 +4007,99 @@ namespace libsemigroups { s.add_pruner(ip); REQUIRE(s.number_of_congruences(12) == 12); // computed using GAP } + + LIBSEMIGROUPS_TEST_CASE("Sims1", + "124", + "Right congruence checking", + "[quick][low-index]") { + Presentation p; + p.alphabet(01_w); + p.contains_empty_word(true); + presentation::add_rule(p, 000_w, 11_w); + presentation::add_rule(p, 001_w, 10_w); + + word_graph_type wg; + + // Wrong alphabet size + wg = to_word_graph(3, {{1, 1, 1}, {2, 2, 2}, {2, 2, 2}}); + wg.number_of_active_nodes(3); + REQUIRE(!sims::is_right_congruence(p, wg)); + + // Incomplete + wg = to_word_graph(2, {{1, 1}, {1, UNDEFINED}}); + wg.number_of_active_nodes(2); + REQUIRE(!sims::is_right_congruence(p, wg)); + + // Incompatible + wg = to_word_graph(2, {{1, 1}, {1, 0}}); + wg.number_of_active_nodes(2); + REQUIRE(!sims::is_right_congruence(p, wg)); + REQUIRE_THROWS_AS(sims::validate_right_congruence(p, wg), + LibsemigroupsException); + + // Works + wg = to_word_graph(4, {{1, 2}, {2, 2}, {3, 3}, {3, 3}}); + wg.number_of_active_nodes(4); + REQUIRE(sims::is_right_congruence(p, wg)); + + // Non maximal + wg = to_word_graph(2, {{1, 1}, {1, 0}}); + wg.number_of_active_nodes(2); + REQUIRE(!sims::is_maximal_right_congruence(p, wg)); + wg = to_word_graph(4, {{1, 2}, {2, 2}, {3, 3}, {3, 3}}); + wg.number_of_active_nodes(4); + REQUIRE(!sims::is_maximal_right_congruence(p, wg)); + wg = to_word_graph(1, {{0, 0}}); + wg.number_of_active_nodes(1); + REQUIRE(!sims::is_maximal_right_congruence(p, wg)); + + // Is maximal + wg = to_word_graph(2, {{1, 1}, {1, 1}}); + wg.number_of_active_nodes(2); + REQUIRE(sims::is_maximal_right_congruence(p, wg)); + } + + LIBSEMIGROUPS_TEST_CASE("Sims2", + "125", + "Two-sided congruence checking", + "[quick][low-index]") { + Presentation p; + p.alphabet(01_w); + p.contains_empty_word(true); + presentation::add_rule(p, 000_w, 11_w); + presentation::add_rule(p, 001_w, 10_w); + + word_graph_type wg; + + // Wrong alphabet size + wg = to_word_graph(3, {{1, 1, 1}, {2, 2, 2}, {2, 2, 2}}); + wg.number_of_active_nodes(3); + REQUIRE(!sims::is_two_sided_congruence(p, wg)); + + // Incomplete + wg = to_word_graph(2, {{1, 1}, {1, UNDEFINED}}); + wg.number_of_active_nodes(2); + REQUIRE(!sims::is_two_sided_congruence(p, wg)); + + // Incompatible + wg = to_word_graph(2, {{1, 1}, {1, 0}}); + wg.number_of_active_nodes(2); + REQUIRE(!sims::is_two_sided_congruence(p, wg)); + REQUIRE_THROWS_AS(sims::validate_two_sided_congruence(p, wg), + LibsemigroupsException); + + // Not compatible with X_Gamma + wg = to_word_graph(4, {{1, 2}, {2, 2}, {3, 3}, {3, 3}}); + wg.number_of_active_nodes(4); + REQUIRE(!sims::is_two_sided_congruence(p, wg)); + REQUIRE_THROWS_AS(sims::validate_two_sided_congruence(p, wg), + LibsemigroupsException); + + // Works + wg = to_word_graph(2, {{1, 1}, {1, 1}}); + wg.number_of_active_nodes(2); + REQUIRE(sims::is_two_sided_congruence(p, wg)); + } } // namespace libsemigroups // [[[0, 0, 0]], #1#