Skip to content

Commit 5b65d02

Browse files
Rewriters: Add generation tests
1 parent 2525ba0 commit 5b65d02

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

tests/test-rewriters.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,5 +504,74 @@ namespace libsemigroups {
504504
++start;
505505
REQUIRE(start == end);
506506
}
507+
508+
LIBSEMIGROUPS_TEST_CASE("OverlapIteratorTrie",
509+
"017",
510+
"different generations",
511+
"[quick]") {
512+
auto rg = ReportGuard(false);
513+
RewritingSystemTrie<ShortLexCompare> rt;
514+
rt.increase_alphabet_size_by(2);
515+
516+
// Words added in generation 0
517+
rewriting_system::add_rule(rt, "abba"_w, "aaa"_w);
518+
rewriting_system::add_rule(rt, "abab"_w, "bbb"_w);
519+
rt.reduce();
520+
521+
// Word added in generation 1
522+
rt.trie().increment_generation();
523+
rewriting_system::add_rule(rt, "baa"_w, "a"_w);
524+
rt.reduce();
525+
526+
{
527+
auto const& trie = rt.trie();
528+
529+
// Should only find the overlaps between
530+
auto start = OverlapIteratorTrie(trie);
531+
auto end = OverlapIteratorTrie();
532+
533+
v4::ToWord toword(std::string({0, 1}));
534+
535+
REQUIRE(toword(start->lhs->lhs()) == "baa"_w);
536+
REQUIRE(toword(start->lhs->rhs()) == "a"_w);
537+
REQUIRE(toword(start->rhs->lhs()) == "abba"_w);
538+
REQUIRE(toword(start->rhs->rhs()) == "aaa"_w);
539+
REQUIRE(start->length == 1);
540+
541+
++start;
542+
REQUIRE(toword(start->lhs->lhs()) == "baa"_w);
543+
REQUIRE(toword(start->lhs->rhs()) == "a"_w);
544+
REQUIRE(toword(start->rhs->lhs()) == "abab"_w);
545+
REQUIRE(toword(start->rhs->rhs()) == "bbb"_w);
546+
REQUIRE(start->length == 1);
547+
548+
++start;
549+
REQUIRE(toword(start->lhs->lhs()) == "abba"_w);
550+
REQUIRE(toword(start->lhs->rhs()) == "aaa"_w);
551+
REQUIRE(toword(start->rhs->lhs()) == "baa"_w);
552+
REQUIRE(toword(start->rhs->rhs()) == "a"_w);
553+
REQUIRE(start->length == 2);
554+
555+
++start;
556+
REQUIRE(toword(start->lhs->lhs()) == "abab"_w);
557+
REQUIRE(toword(start->lhs->rhs()) == "bbb"_w);
558+
REQUIRE(toword(start->rhs->lhs()) == "baa"_w);
559+
REQUIRE(toword(start->rhs->rhs()) == "a"_w);
560+
REQUIRE(start->length == 1);
561+
562+
++start;
563+
REQUIRE(start == end);
564+
}
565+
566+
rt.increase_alphabet_size_by(1);
567+
568+
// Word added in generation 2
569+
rt.trie().increment_generation();
570+
rewriting_system::add_rule(rt, "c"_w, "b"_w);
571+
rt.reduce();
572+
573+
// No overlaps where at least one word is in generation 2
574+
REQUIRE(OverlapIteratorTrie(rt.trie()) == OverlapIteratorTrie());
575+
}
507576
} // namespace detail
508577
} // namespace libsemigroups

0 commit comments

Comments
 (0)