formalang/tests/DFAToMinDFA/CountSizesMinDFA.cpp

41 lines
1.2 KiB
C++
Raw Permalink Normal View History

2021-10-10 22:13:50 +00:00
#include <gtest/gtest.h>
#include "regular/RegularTree.hpp"
#include "converters/RegularToNFA.hpp"
#include "converters/NFAToDFA.hpp"
#include "converters/DFAToMinDFA.hpp"
#include "converters/DFAToRegular.hpp"
using namespace regular;
using namespace NFA;
using namespace DFA;
using namespace converters;
size_t GetCountVertexes(const std::string& regular) {
RegularTree r(regular);
NFAGraph NFA_tree = RegularToNFAGraph(std::move(r));
DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree));
DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph));
return DFA_graph.GetReallyCountVertexes();
}
TEST(DFA_to_min_DFA, a_start) {
EXPECT_EQ(GetCountVertexes("a*"), GetCountVertexes("( a | )*| | | aaa a a"));
}
TEST(DFA_to_min_DFA, a_plus) {
EXPECT_EQ(GetCountVertexes("a+"), GetCountVertexes("( a | a a )+|a | a |a "));
}
TEST(DFA_to_min_DFA, a_star_or_b_star) {
EXPECT_EQ(GetCountVertexes("a*|b*"), GetCountVertexes("a|b|a*|a+|b*|b+|bbb b b b| a a aa a aa | a+"));
}
TEST(DFA_to_min_DFA, epsilon) {
EXPECT_EQ(GetCountVertexes(" "), GetCountVertexes(" | | | "));
}
TEST(DFA_to_min_DFA, a_or_b_star) {
EXPECT_EQ(GetCountVertexes("(a|b)*"), GetCountVertexes("a+|b+|a*|b*|a*b*a*|a|b(a|b)*|b| |(a|b)*"));
}