diff --git a/alib2data/test-src/automaton/AutomatonTemplatesTest.cpp b/alib2data/test-src/automaton/AutomatonTemplatesTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd9abf6f26a92d4d450940a5da963a032abbd417 --- /dev/null +++ b/alib2data/test-src/automaton/AutomatonTemplatesTest.cpp @@ -0,0 +1,76 @@ +#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 ); + } +} diff --git a/alib2data/test-src/automaton/AutomatonTemplatesTest.h b/alib2data/test-src/automaton/AutomatonTemplatesTest.h new file mode 100644 index 0000000000000000000000000000000000000000..549040f12f8b8d96c972759ec5b752537293d01e --- /dev/null +++ b/alib2data/test-src/automaton/AutomatonTemplatesTest.h @@ -0,0 +1,18 @@ +#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_