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

another leftFactorize test

parent c7cddd55
No related branches found
No related tags found
No related merge requests found
...@@ -13,12 +13,6 @@ void LeftFactorize::tearDown ( ) { ...@@ -13,12 +13,6 @@ void LeftFactorize::tearDown ( ) {
} }
   
void LeftFactorize::testLeftFactorize ( ) { void LeftFactorize::testLeftFactorize ( ) {
}
void LeftFactorize::testLeftFactorize2 ( ) {
}
void LeftFactorize::testLeftFactorize3 ( ) {
alphabet::Symbol S = alphabet::symbolFrom ( "S" ); alphabet::Symbol S = alphabet::symbolFrom ( "S" );
alphabet::Symbol Sp = alphabet::symbolFrom ( "S'" ); alphabet::Symbol Sp = alphabet::symbolFrom ( "S'" );
alphabet::Symbol B = alphabet::symbolFrom ( "B" ); alphabet::Symbol B = alphabet::symbolFrom ( "B" );
...@@ -68,3 +62,63 @@ void LeftFactorize::testLeftFactorize3 ( ) { ...@@ -68,3 +62,63 @@ void LeftFactorize::testLeftFactorize3 ( ) {
   
CPPUNIT_ASSERT ( res == comp ); CPPUNIT_ASSERT ( res == comp );
} }
void LeftFactorize::testLeftFactorize2 ( ) {
alphabet::Symbol S = alphabet::symbolFrom ( "S" );
alphabet::Symbol Sp = alphabet::symbolFrom ( "S'" );
alphabet::Symbol B = alphabet::symbolFrom ( "B" );
alphabet::Symbol Bp = alphabet::symbolFrom ( "B'" );
alphabet::Symbol C = alphabet::symbolFrom ( "C" );
alphabet::Symbol Cp = alphabet::symbolFrom ( "C'" );
alphabet::Symbol D = alphabet::symbolFrom ( "D" );
alphabet::Symbol a = alphabet::symbolFrom ( 'a' );
alphabet::Symbol b = alphabet::symbolFrom ( 'b' );
alphabet::Symbol c = alphabet::symbolFrom ( 'c' );
alphabet::Symbol d = alphabet::symbolFrom ( 'd' );
grammar::CFG grammar ( S );
grammar.setTerminalAlphabet ( { a, b, c, d } );
grammar.setNonterminalAlphabet ( { { S, B, C, D } } );
grammar.setInitialSymbol ( S );
grammar.addRule ( S, std::vector < alphabet::Symbol > { a, B } );
grammar.addRule ( S, std::vector < alphabet::Symbol > { a, C } );
grammar.addRule ( S, std::vector < alphabet::Symbol > { D } );
grammar.addRule ( B, std::vector < alphabet::Symbol > { b, B } );
grammar.addRule ( B, std::vector < alphabet::Symbol > { b } );
grammar.addRule ( C, std::vector < alphabet::Symbol > { c, C } );
grammar.addRule ( C, std::vector < alphabet::Symbol > { c } );
grammar.addRule ( C, std::vector < alphabet::Symbol > { b } );
grammar.addRule ( D, std::vector < alphabet::Symbol > { d } );
grammar::CFG res = grammar;
grammar::parsing::LeftFactorize::leftFactorize ( res, a, S);
grammar::parsing::LeftFactorize::leftFactorize ( res, b, B);
grammar::parsing::LeftFactorize::leftFactorize ( res, c, C);
grammar::CFG comp ( S );
comp.setTerminalAlphabet ( { a, b, c, d } );
comp.setNonterminalAlphabet ( { { S, Sp, B, Bp, C, Cp, D} } );
comp.setInitialSymbol ( S );
comp.addRule ( S, std::vector < alphabet::Symbol > { a, Sp } );
comp.addRule ( S, std::vector < alphabet::Symbol > { D } );
comp.addRule ( Sp, std::vector < alphabet::Symbol > { B } );
comp.addRule ( Sp, std::vector < alphabet::Symbol > { C } );
comp.addRule ( B, std::vector < alphabet::Symbol > { b, Bp } );
comp.addRule ( Bp, std::vector < alphabet::Symbol > { B } );
comp.addRule ( Bp, std::vector < alphabet::Symbol > { } );
comp.addRule ( C, std::vector < alphabet::Symbol > { c, Cp } );
comp.addRule ( C, std::vector < alphabet::Symbol > { b } );
comp.addRule ( Cp, std::vector < alphabet::Symbol > { C } );
comp.addRule ( Cp, std::vector < alphabet::Symbol > { } );
comp.addRule ( D, std::vector < alphabet::Symbol > { d } );
std::cout << res << std::endl << comp << std::endl;
CPPUNIT_ASSERT ( res == comp );
}
...@@ -7,7 +7,6 @@ class LeftFactorize : public CppUnit::TestFixture { ...@@ -7,7 +7,6 @@ class LeftFactorize : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE ( LeftFactorize ); CPPUNIT_TEST_SUITE ( LeftFactorize );
CPPUNIT_TEST ( testLeftFactorize ); CPPUNIT_TEST ( testLeftFactorize );
CPPUNIT_TEST ( testLeftFactorize2 ); CPPUNIT_TEST ( testLeftFactorize2 );
CPPUNIT_TEST ( testLeftFactorize3 );
CPPUNIT_TEST_SUITE_END ( ); CPPUNIT_TEST_SUITE_END ( );
   
public: public:
...@@ -16,7 +15,6 @@ public: ...@@ -16,7 +15,6 @@ public:
   
void testLeftFactorize ( ); void testLeftFactorize ( );
void testLeftFactorize2 ( ); void testLeftFactorize2 ( );
void testLeftFactorize3 ( );
}; };
   
#endif /* LEFT_FACTORIZE_TEST_H_ */ #endif /* LEFT_FACTORIZE_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