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

proof of concept of templated algorithms

parent 91698c54
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@
 
#include <factory/StringDataFactory.hpp>
 
#include <primitive/Character.h>
#define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y))
#define CPPUNIT_EXCLUSIVE_OR(x, y) CPPUNIT_ASSERT((!(x) && (y)) || ((x) && !(y)))
 
......@@ -65,3 +67,93 @@ void RegExpOptimizeTest::testOptimize() {
 
}
 
void RegExpOptimizeTest::testOptimizeTemplated() {
regexp::UnboundedRegExpSymbol < char > a ( 'a' );
regexp::UnboundedRegExpSymbol < char > b ( 'b' );
// regexp::UnboundedRegExpSymbol < char > z ( 'z' );
{
regexp::UnboundedRegExpAlternation < char > alt;
alt.appendElement ( a );
alt.appendElement ( a );
regexp::UnboundedRegExp < char > regexp ( regexp::UnboundedRegExpStructure < char > { alt } );
regexp::UnboundedRegExp < char > res = regexp::simplify::RegExpOptimize::optimize(regexp);
regexp::UnboundedRegExp < char > regexpRes( regexp::UnboundedRegExpStructure < char > { a } );
std::cout << res << std::endl;
std::cout << regexpRes << std::endl;
CPPUNIT_ASSERT ( regexpRes == res );
}
{
regexp::UnboundedRegExpAlternation < char > alt1;
alt1.appendElement ( a );
alt1.appendElement ( a );
regexp::UnboundedRegExpConcatenation < char > con1;
con1.appendElement ( alt1 );
con1.appendElement ( b );
regexp::UnboundedRegExpConcatenation < char > con2;
con2.appendElement ( regexp::UnboundedRegExpEmpty < char > { } );
con2.appendElement ( b );
regexp::UnboundedRegExpAlternation < char > alt2;
alt2.appendElement ( con2 );
alt2.appendElement ( a );
regexp::UnboundedRegExpConcatenation < char > con3;
con3.appendElement ( regexp::UnboundedRegExpEmpty < char > { } );
con3.appendElement ( a );
regexp::UnboundedRegExpAlternation < char > alt3;
alt3.appendElement ( con3 );
alt3.appendElement ( alt2 );
regexp::UnboundedRegExpConcatenation < char > con4;
con4.appendElement ( regexp::UnboundedRegExpEmpty < char > { } );
con4.appendElement ( b );
regexp::UnboundedRegExpAlternation < char > alt4;
alt4.appendElement ( con4 );
alt4.appendElement ( alt3 );
regexp::UnboundedRegExpAlternation < char > alt5;
alt5.appendElement ( con1 );
alt5.appendElement ( alt4 );
regexp::UnboundedRegExp < char > regexp ( regexp::UnboundedRegExpStructure < char > { alt5 } );
regexp::UnboundedRegExp < char > res = regexp::simplify::RegExpOptimize::optimize ( regexp );
regexp::UnboundedRegExpConcatenation < char > con6;
con6.appendElement ( a );
con6.appendElement ( b );
regexp::UnboundedRegExpAlternation < char > alt6;
alt6.appendElement ( a );
alt6.appendElement ( con6 );
regexp::UnboundedRegExp < char > regexpRes( regexp::UnboundedRegExpStructure < char > { alt6 } );
std::cout << regexp << std::endl;
std::cout << res << std::endl;
std::cout << regexpRes << std::endl;
CPPUNIT_ASSERT ( regexpRes == res );
}
/* {
std::string input = "a z + a b* b z";
regexp::UnboundedRegExp < > regexp( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) );
regexp::UnboundedRegExp < > res = regexp::simplify::RegExpOptimize::optimize(regexp);
std::string inputRes = "a b* z";
regexp::UnboundedRegExp < > regexpRes( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(inputRes).getData() ) );
std::cout << res << std::endl;
std::cout << regexpRes << std::endl;
CPPUNIT_ASSERT ( regexpRes == res );
}*/
}
......@@ -7,6 +7,7 @@ class RegExpOptimizeTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( RegExpOptimizeTest );
CPPUNIT_TEST( testOptimize );
CPPUNIT_TEST( testOptimizeTemplated );
CPPUNIT_TEST_SUITE_END();
 
public:
......@@ -14,6 +15,7 @@ public:
void tearDown();
 
void testOptimize();
void testOptimizeTemplated();
};
 
#endif // REG_EXP_OPTIMIZE_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