Skip to content
Snippets Groups Projects
Commit 4229fb1d authored by Jan Trávníček's avatar Jan Trávníček
Browse files

test templating of data structures

parent 11228175
No related branches found
No related tags found
No related merge requests found
#include "AutomatonTemplatesTest.h"
#include "sax/SaxParseInterface.h"
#include "sax/SaxComposeInterface.h"
#include "automaton/FSM/DFA.h"
#include "automaton/AutomatonException.h"
#include "factory/XmlDataFactory.hpp"
#include <primitive/Integer.h>
#include <primitive/Character.h>
#include <object/Object.h>
#define CPPUNIT_IMPLY( x, y ) CPPUNIT_ASSERT ( !( x ) || ( y ) )
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( AutomatonTemplatesTest, "automaton" );
CPPUNIT_TEST_SUITE_REGISTRATION ( AutomatonTemplatesTest );
void AutomatonTemplatesTest::setUp ( ) {
}
void AutomatonTemplatesTest::tearDown ( ) {
}
void AutomatonTemplatesTest::testDFAParser ( ) {
automaton::DFA < char, int > automaton ( 1 );
automaton.addState ( 2 );
automaton.addState ( 3 );
automaton.addInputSymbol ( 'a' );
automaton.addInputSymbol ( 'b' );
automaton.addTransition ( 1, 'a', 2 );
automaton.addTransition ( 2, 'b', 1 );
automaton.addFinalState ( 3 );
CPPUNIT_ASSERT ( automaton == automaton );
{
std::deque < sax::Token > tokens = alib::XmlDataFactory::toTokens ( automaton );
std::string tmp;
sax::SaxComposeInterface::printMemory ( tmp, tokens );
std::deque < sax::Token > tokens2;
sax::SaxParseInterface::parseMemory ( tmp, tokens2 );
automaton::DFA < char, int > automaton2 = alib::XmlDataFactory::fromTokens < automaton::DFA < char, int > > ( std::move ( tokens2 ) );
CPPUNIT_ASSERT ( automaton == automaton2 );
}
{
std::deque < sax::Token > tokens = alib::XmlDataFactory::toTokens ( automaton );
std::string tmp;
sax::SaxComposeInterface::printMemory ( tmp, tokens );
std::deque < sax::Token > tokens2;
sax::SaxParseInterface::parseMemory ( tmp, tokens2 );
automaton::DFA < alib::Object, alib::Object > automaton2 = alib::XmlDataFactory::fromTokens < automaton::DFA < alib::Object, alib::Object > > ( std::move ( tokens2 ) );
automaton::DFA < alib::Object, alib::Object > automaton3 ( alib::Object ( primitive::Integer ( 1 ) ) );
automaton3.addState ( alib::Object ( primitive::Integer ( 2 ) ) );
automaton3.addState ( alib::Object ( primitive::Integer ( 3 ) ) );
automaton3.addInputSymbol ( alib::Object ( primitive::Character ( 'a' ) ) );
automaton3.addInputSymbol ( alib::Object ( primitive::Character ( 'b' ) ) );
automaton3.addTransition ( alib::Object ( primitive::Integer ( 1 ) ), alib::Object ( primitive::Character ( 'a' ) ), alib::Object ( primitive::Integer ( 2 ) ) );
automaton3.addTransition ( alib::Object ( primitive::Integer ( 2 ) ), alib::Object ( primitive::Character ( 'b' ) ), alib::Object ( primitive::Integer ( 1 ) ) );
automaton3.addFinalState ( alib::Object ( primitive::Integer ( 3 ) ) );
CPPUNIT_ASSERT ( automaton2 == automaton3 );
}
}
#ifndef AUTOMATON_TEST_H_
#define AUTOMATON_TEST_H_
#include <cppunit/extensions/HelperMacros.h>
class AutomatonTemplatesTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE ( AutomatonTemplatesTest );
CPPUNIT_TEST ( testDFAParser );
CPPUNIT_TEST_SUITE_END ( );
public:
void setUp ( );
void tearDown ( );
void testDFAParser ( );
};
#endif // AUTOMATON_TEST_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment