Skip to content

Commit

Permalink
works on empty automata
Browse files Browse the repository at this point in the history
  • Loading branch information
koniksedy committed Oct 30, 2024
1 parent 31413b1 commit d2cec6b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/inter-aut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ bool has_atmost_one_auto_naming(const mata::IntermediateAut& aut) {
}
}

// In case of no transition
if (opstack.size() != 1) {
return {};
}

assert(opstack.size() == 1);
return std::move(*opstack.begin());
}
Expand Down
38 changes: 38 additions & 0 deletions tests/nfa/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,44 @@ using Word = std::vector<Symbol>;
TEST_CASE("parse_from_mata()") {
Delta delta;

SECTION("Empty automaton - No initial and final") {
Nfa nfa{ delta, {}, {} };
SECTION("from String") {
std::string empty_nfa_str = "@NFA-explicit\n%Alphabet-auto\n";
Nfa empty_nfa{ mata::nfa::builder::parse_from_mata(empty_nfa_str) };
CHECK(are_equivalent(empty_nfa, nfa));
}

SECTION("from file") {
std::filesystem::path nfa_file{ "./temp-test-parse_from_mata-empty_nfa.mata" };
std::fstream file{ nfa_file, std::fstream::in | std::fstream::out | std::fstream::trunc };
file << "@NFA-explicit\n%Alphabet-auto\n";
file.close();
Nfa parsed{ mata::nfa::builder::parse_from_mata(nfa_file) };
std::filesystem::remove(nfa_file);
CHECK(are_equivalent(parsed, nfa));
}

}

SECTION("Empty automaton with empty final and initial") {
Nfa nfa{ delta, {}, {} };
SECTION("from String") {
std::string empty_nfa_str = "@NFA-explicit\n%Alphabet-auto\n%Initial\n%Final\n";
Nfa empty_nfa{ mata::nfa::builder::parse_from_mata(empty_nfa_str) };
CHECK(are_equivalent(empty_nfa, nfa));
}
SECTION("from file") {
std::filesystem::path nfa_file{ "./temp-test-parse_from_mata-empty_nfa-empty_initial_final.mata" };
std::fstream file{ nfa_file, std::fstream::in | std::fstream::out | std::fstream::trunc };
file << "@NFA-explicit\n%Alphabet-auto\n%Initial\n%Final\n";
file.close();
Nfa parsed{ mata::nfa::builder::parse_from_mata(nfa_file) };
std::filesystem::remove(nfa_file);
CHECK(are_equivalent(parsed, nfa));
}
}

SECTION("Simple automaton") {
delta.add(0, 0, 0);
delta.add(0, 1, 1);
Expand Down

0 comments on commit d2cec6b

Please sign in to comment.