Skip to content
Snippets Groups Projects
trimTest.cpp 2.42 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include <list>
    #include "trimTest.h"
    
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    #include "automaton/simplify/Trim.h"
    
    #include "grammar/simplify/Trim.h"
    
    
    #include "automaton/FSM/DFA.h"
    #include "grammar/Regular/RightRG.h"
    
    
    CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( trimTest, "automaton" );
    
    CPPUNIT_TEST_SUITE_REGISTRATION( trimTest );
    
    void trimTest::setUp() {
    }
    
    void trimTest::tearDown() {
    }
    
    void trimTest::testTrimAutomaton() {
    
      automaton::DFA < > automaton(DefaultStateType(1));
    
      automaton.addState(DefaultStateType(1));
      automaton.addState(DefaultStateType(2));
      automaton.addState(DefaultStateType(3));
      automaton.addInputSymbol(DefaultSymbolType("a"));
      automaton.addInputSymbol(DefaultSymbolType("b"));
    
      automaton.addTransition(DefaultStateType(1), DefaultSymbolType("a"), DefaultStateType(2));
      automaton.addTransition(DefaultStateType(2), DefaultSymbolType("b"), DefaultStateType(1));
      automaton.addTransition(DefaultStateType(3), DefaultSymbolType("b"), DefaultStateType(1));
    
      automaton.addFinalState(DefaultStateType(1));
    
      automaton::DFA<> trimed = automaton::simplify::Trim::trim(automaton);
    
    
      CPPUNIT_ASSERT(trimed.getStates().size() == 2);
    }
    
    void trimTest::testTrimGrammar() {
    
      grammar::RightRG < > rrGrammar(DefaultSymbolType(1));
    
      rrGrammar.addNonterminalSymbol(DefaultSymbolType(1));
      rrGrammar.addNonterminalSymbol(DefaultSymbolType(2));
      rrGrammar.addNonterminalSymbol(DefaultSymbolType(3));
      rrGrammar.addNonterminalSymbol(DefaultSymbolType(4));
      rrGrammar.addNonterminalSymbol(DefaultSymbolType(5));
      rrGrammar.addNonterminalSymbol(DefaultSymbolType(6));
      rrGrammar.addTerminalSymbol(DefaultSymbolType("a"));
      rrGrammar.addTerminalSymbol(DefaultSymbolType("b"));
    
      rrGrammar.addRule(DefaultSymbolType(1), std::make_pair(DefaultSymbolType("a"), DefaultSymbolType(2)));
      rrGrammar.addRule(DefaultSymbolType(2), std::make_pair(DefaultSymbolType("b"), DefaultSymbolType(3)));
      rrGrammar.addRule(DefaultSymbolType(3), DefaultSymbolType("a"));
    
      rrGrammar.addRule(DefaultSymbolType(4), std::make_pair(DefaultSymbolType("b"), DefaultSymbolType(5)));
      rrGrammar.addRule(DefaultSymbolType(5), DefaultSymbolType("a"));
      rrGrammar.addRule(DefaultSymbolType(5), std::make_pair(DefaultSymbolType("b"), DefaultSymbolType(2)));
      rrGrammar.addRule(DefaultSymbolType(6), std::make_pair(DefaultSymbolType("b"), DefaultSymbolType(6)));
    
      grammar::RightRG < > trimed = grammar::simplify::Trim::trim(rrGrammar);
    
    
      CPPUNIT_ASSERT(trimed.getNonterminalAlphabet().size() == 3);
    }