18 std::string name =
"AnnotatePdStates Renaming";
19 std::cout <<
"Testing " << name <<
" ..." << std::endl;
21 std::string renameString =
"old";
27 StateSet::Iterator its;
33 throw Exception(name,
"MergeStateAnnotation not set.", 1003);
34 if(msa->
Annotation().compare(renameString) != 0){
35 std::stringstream errstr;
36 errstr <<
"Annotation incorrect, was " << msa->
Annotation() <<
", but " << renameString <<
" was expected." << std::endl;
37 throw Exception(name, errstr.str(), 1003);
43 std::cout <<
"Finished " << name << std::endl;
50 std::string name =
"AnnotatePdStates Number of States";
51 std::cout <<
"Testing " << name <<
" ..." << std::endl;
53 std::string renameString =
"old";
60 std::stringstream errstr;
61 errstr <<
"Incorrect, number of states, was " << g1.
Size() <<
", but " << g2.
Size() <<
" was expected." << std::endl;
62 throw Exception(name, errstr.str(), 1003);
67 std::cout <<
"Finished " << name << std::endl;
74 std::string name =
"RenameStackSymbold Renaming Stack Symbols";
75 std::cout <<
"Testing " << name <<
" ..." <<std::endl;
77 std::string renameString =
"old";
83 StackSymbolSet::Iterator it;
88 std::stringstream errstr;
89 errstr <<
"Annotation incorrect, " << g2.
StackSymbolName(*it) <<
" was expected, but not found in the stack symbol list:\n" ;
90 StackSymbolSet::Iterator iterr;
95 throw Exception(name, errstr.str(), 1003);
101 std::stringstream errstr;
102 errstr <<
"Annotation incorrect, " << renameString <<
"-" << g2.
StackSymbolName(*it) <<
" was expected, but not found in the stack symbol list:\n" ;
103 StackSymbolSet::Iterator iterr;
108 throw Exception(name, errstr.str(), 1003);
116 std::cout <<
"Finished " << name << std::endl;
123 std::string name =
"RenameStackSymbold Number of Stack Symbols";
124 std::cout <<
"Testing " << name <<
" ..." << std::endl;
126 std::string renameString =
"old";
133 std::stringstream errstr;
135 throw Exception(name, errstr.str(), 1003);
140 std::cout <<
"Finished " << name << std::endl;
150 std::string name =
"RenameStackSymbold Renaming Transitions";
151 std::cout <<
"Testing " << name <<
" ..." << std::endl;
153 std::string renameString =
"old";
159 std::vector<Idx> oldPush, oldPop, push, pop;
160 std::vector<Idx>::const_iterator pushit, popit;
162 PopPushSet::const_iterator ppit;
168 for(ppit = popPush.begin(); ppit != popPush.end(); ppit++){
171 oldPop = ppit->first;
172 for(popit = oldPop.begin(); popit != oldPop.end(); popit++){
176 std::string annotation = g2.
StackSymbolName(*popit).substr(0, renameString.size() + 1);
177 if(annotation.compare(renameString +
"-") != 0){
178 std::stringstream errstr;
179 errstr <<
"Annotation incorrect, " << renameString <<
"- was expected, but symbol was " << g2.
StackSymbolName(*popit) << std::endl;
180 throw Exception(name, errstr.str(), 1003);
186 oldPush = ppit->second;
187 for(pushit = oldPush.begin(); pushit != oldPush.end(); pushit++){
191 std::string annotation = g2.
StackSymbolName(*pushit).substr(0, renameString.size() + 1);
192 if(annotation.compare(renameString +
"-") != 0){
193 std::stringstream errstr;
194 errstr <<
"Annotation incorrect, " << renameString <<
"- was expected, but symbol was " << g2.
StackSymbolName(*pushit) << std::endl;
195 throw Exception(name, errstr.str(), 1003);
206 std::cout <<
"Finished " << name << std::endl;
213 std::string name =
"RemoveLambdaPop No Lambda Pop";
214 std::cout <<
"Testing " << name <<
" ..." << std::endl;
223 PopPushSet::const_iterator ppsit;
228 for(ppsit = g2.
PopPush(*tit).begin(); ppsit != g2.
PopPush(*tit).end(); ppsit++){
230 std::stringstream errstr;
231 errstr <<
"Lambda popping edges not removed, Lambda pop found in transition" << g2.
TransRel().
Str(*tit) << std::endl;
232 throw Exception(name, errstr.str(), 1003);
239 std::cout <<
"Finished " << name << std::endl;
246 std::string name =
"RemoveLambdaPop All Expecting Transition";
247 std::cout <<
"Testing " << name <<
" ..." << std::endl;
254 PopPushSet::const_iterator ppsit;
260 for(ppsit = g1.
PopPush(*tit).begin(); ppsit != g1.
PopPush(*tit).end(); ppsit++){
270 std::cout <<
"warning: cannot perform test, because there is no lambda pop in the original generator" << std::endl;
279 std::vector<Idx> pop, push;
280 std::vector<Idx>::const_iterator popit, pushit;
281 StackSymbolSet::Iterator ssit;
282 bool transFound, symbolFound;
295 for(ppsit = g2.
PopPush(*tit).begin(); ppsit != g2.
PopPush(*tit).end(); ppsit++){
298 push = ppsit->second;
300 if(pop.front() == *ssit && *push.rbegin() == *ssit){
312 if(transFound)
break;
316 std::stringstream errstr;
317 errstr <<
"Original generator has lambda popping edge, but result generator has no edge that accepts all stack symbols" << std::endl;
318 throw Exception(name, errstr.str(), 1003);
323 std::cout <<
"Finished " << name << std::endl;
331 std::string name =
"RemoveMultPop Number of States and Transitions";
337 Idx expectedNumberTransitions = 11;
338 Idx expectedNumberStates = 10;
345 if(g2.
Size() != expectedNumberStates){
346 std::stringstream errstr;
347 errstr <<
"Number of states was " << g2.
Size() <<
", but " << expectedNumberStates <<
" was expected." << std::endl;
348 throw Exception(name, errstr.str(), 1003);
353 std::stringstream errstr;
354 errstr <<
"Number of transitions incorrect" << g2.
TransRelSize() <<
", but " << expectedNumberTransitions <<
" was expected." << std::endl;
355 throw Exception(name, errstr.str(), 1003);
406 std::string name =
"SPDA Read Pop Push Only";
414 PopPushSet::const_iterator ppit;
415 std::vector<Idx> pop, push;
416 std::vector<Idx>::const_iterator ssit;
440 pop.front() == push.back()){
445 std::stringstream errstr;
446 errstr <<
"Transition (" << transit->X1 <<
", " << g2.
EventName(transit->Ev) <<
", " << transit->X2 <<
") with pop [";
447 for(ssit = pop.begin(); ssit != pop.end(); ssit++){
450 errstr <<
"] and push [";
451 for(ssit = push.begin(); ssit != push.end(); ssit++){
454 errstr <<
"] was neither read nor pop nor push." << std::endl;
455 throw Exception(name, errstr.str(), 1003);
469 std::string name =
"Nda Active Passive";
478 std::stringstream errstr;
479 errstr <<
"Number of states incorrect, was" << g2.
States().Size() <<
", but " << 2*g1.
States().Size() <<
" was expected." << std::endl;
480 throw Exception(name, errstr.str(), 1003);
483 StateSet::Iterator stateit;
492 throw Exception(name,
"MergeStateAnnotation not set.", 1003);
497 else if(msa->
Annotation().compare(
"passive") == 0){
501 std::stringstream errstr;
502 errstr <<
"Annotation incorrect, was " << msa->
Annotation() <<
", but either active or passive was expected." << std::endl;
503 throw Exception(name, errstr.str(), 1003);
506 if(active != passive){
507 std::stringstream errstr;
508 errstr <<
"There were " << active <<
" active states and " << passive <<
" passive states, but equal numbers were expected." << std::endl;
509 throw Exception(name, errstr.str(), 1003);
522 std::string name =
"Nda Transitions";
529 std::set<std::pair<Idx,Idx> > expectedTransitions;
530 expectedTransitions.insert(std::make_pair(1,3));
531 expectedTransitions.insert(std::make_pair(1,5));
532 expectedTransitions.insert(std::make_pair(2,3));
533 expectedTransitions.insert(std::make_pair(2,6));
534 expectedTransitions.insert(std::make_pair(3,8));
535 expectedTransitions.insert(std::make_pair(4,8));
536 expectedTransitions.insert(std::make_pair(5,3));
537 expectedTransitions.insert(std::make_pair(6,4));
538 expectedTransitions.insert(std::make_pair(7,6));
539 expectedTransitions.insert(std::make_pair(8,6));
545 if(expectedTransitions.erase(std::make_pair(transit->X1, transit->X2)) == 0){
546 std::stringstream errstr;
547 errstr <<
"Transition from state " << transit->X1 <<
" to state " << transit->X2 <<
" found, but was not expected." << std::endl;
548 throw Exception(name, errstr.str(), 1003);
552 if(expectedTransitions.size() != 0){
553 std::stringstream errstr;
554 errstr <<
"Not all expected transitions were found." << std::endl;
555 throw Exception(name, errstr.str(), 1003);
618 std::string name =
"Filter Mixed Grammar Symbols";
624 std::set<Terminal>::const_iterator tit;
625 std::vector<TerminalPtr> tpv;
626 std::vector<TerminalPtr>::iterator tpvit;
627 std::set<Nonterminal> rSet;
634 word.push_back(ntPtr);
641 word.push_back(tPtr);
648 if(rSet.size() != 1){
649 std::stringstream errstr;
650 errstr <<
"size of result set is " << rSet.size() <<
", but 1 was expected" << std::endl;
651 throw Exception(name, errstr.str(), 1003);
656 std::stringstream errstr;
657 errstr <<
"result set did not contain the expected nonterminal " << gr1.
Nonterminals().begin()->Str() << std::endl;
658 throw Exception(name, errstr.str(), 1003);
662 std::cout << (*rSet.begin()).Str() << std::endl;
663 std::cout << (*gr1.
Nonterminals().begin()).Str() << std::endl;
673 std::string name =
"Filter Nothing";
676 std::set<Nonterminal> nt;
679 std::set<Nonterminal> rSet =
Filter(nt,gs);
683 if(rSet.size() != 0){
684 std::stringstream errstr;
685 errstr <<
"size of result set is " << rSet.size() <<
", but 0 was expected" << std::endl;
686 throw Exception(name, errstr.str(), 1003);
699 std::string name =
"Rnpp1 Find Symbols Empty Set";
710 std::cout <<
"Warning, test parameters seem to be wrong. The test grammar did not contain Nonterminal (5,[3],1)." << std::endl;
715 std::set<Nonterminal> ntSet;
717 std::set<Nonterminal> rSet =
Rnpp1(gr,ntSet);
721 if(rSet.size() != 1){
722 std::stringstream errstr;
723 errstr <<
"size of result set is " << rSet.size() <<
", but 1 was expected" << std::endl;
724 throw Exception(name, errstr.str(), 1003);
727 if(*rSet.begin() != nt){
728 std::stringstream errstr;
729 errstr <<
"result set did not contain the expected nonterminal " << nt.
Str() << std::endl;
730 throw Exception(name, errstr.str(), 1003);
743 std::string name =
"Rnpp1 Find Symbols Empty Set";
754 std::cout <<
"Warning, test parameters seem to be wrong. The test grammar did not contain Nonterminal (1,[2],2)." << std::endl;
755 std::cout << gr.
Str() << std::endl;
760 std::set<Nonterminal> ntSet;
762 std::set<Nonterminal> rSet =
Rnpp1(gr,
Rnpp1(gr,ntSet));
766 if(rSet.size() != 2){
767 std::stringstream errstr;
768 errstr <<
"size of result set is " << rSet.size() <<
", but 2 was expected" << std::endl;
769 throw Exception(name, errstr.str(), 1003);
772 if(*rSet.begin() != nt){
773 std::stringstream errstr;
774 errstr <<
"result set did not contain the expected nonterminal " << nt.
Str() << std::endl;
775 throw Exception(name, errstr.str(), 1003);
788 std::string name =
"Rnppl Find Symbols Empty Set";
800 std::set<Nonterminal> ntSet;
802 std::set<Nonterminal> rSet =
Rnppl(gr,ntSet);
806 if(rSet.size() != findThis.size()){
807 std::stringstream errstr;
808 errstr <<
"size of result set is " << rSet.size() <<
", but " << findThis.size() <<
" was expected" << std::endl;
809 throw Exception(name, errstr.str(), 1003);
812 std::set<Nonterminal>::const_iterator ntit, findit;
813 for(ntit = findThis.begin(); ntit != findThis.end(); ntit++){
815 findit = rSet.find(*ntit);
817 if(findit == findThis.end()){
818 std::stringstream errstr;
819 errstr <<
"result set did not contain the expected nonterminal " << ntit->Str() << std::endl;
820 throw Exception(name, errstr.str(), 1003);
834 std::string name =
"Rnppl Find Symbols Nonempty Set";
846 std::set<Nonterminal> ntSet;
847 v.clear(); v.push_back(2);
849 v.clear(); v.push_back(3);
852 std::set<Nonterminal> rSet =
Rnppl(gr,ntSet);
856 if(rSet.size() != findThis.size()){
857 std::stringstream errstr;
858 errstr <<
"size of result set is " << rSet.size() <<
", but " << findThis.size() <<
" was expected" << std::endl;
859 throw Exception(name, errstr.str(), 1003);
862 std::set<Nonterminal>::const_iterator ntit, findit;
863 for(ntit = findThis.begin(); ntit != findThis.end(); ntit++){
865 findit = rSet.find(*ntit);
867 if(findit == findThis.end()){
868 std::stringstream errstr;
869 errstr <<
"result set did not contain the expected nonterminal " << ntit->Str() << std::endl;
870 throw Exception(name, errstr.str(), 1003);
884 std::string name =
"Rnppl Find Symbols Complete Set";
896 std::set<Nonterminal> ntSet = findThis;
898 std::set<Nonterminal> rSet =
Rnppl(gr,ntSet);
902 if(rSet.size() != findThis.size()){
903 std::stringstream errstr;
904 errstr <<
"size of result set is " << rSet.size() <<
", but " << findThis.size() <<
" was expected" << std::endl;
905 throw Exception(name, errstr.str(), 1003);
908 std::set<Nonterminal>::const_iterator ntit, findit;
909 for(ntit = findThis.begin(); ntit != findThis.end(); ntit++){
911 findit = rSet.find(*ntit);
913 if(findit == findThis.end()){
914 std::stringstream errstr;
915 errstr <<
"result set did not contain the expected nonterminal " << ntit->Str() << std::endl;
916 throw Exception(name, errstr.str(), 1003);
930 std::string name =
"Rnpp Grammar 1";
946 v.clear(); v.push_back(2);
954 std::stringstream errstr;
955 errstr <<
"size of nonterminal set is " << rGr.
Nonterminals().size() <<
", but " << finalNtSet.size() <<
" was expected" << std::endl;
956 throw Exception(name, errstr.str(), 1003);
960 std::stringstream errstr;
961 errstr <<
"size of grammar production set is " << rGr.
GrammarProductions().size() <<
", but " << finalGpSet.size() <<
" was expected" << std::endl;
962 throw Exception(name, errstr.str(), 1003);
966 std::set<Nonterminal>::const_iterator ntit, findntit;
967 for(ntit = finalNtSet.begin(); ntit != finalNtSet.end(); ntit++){
971 if(findntit == finalNtSet.end()){
972 std::stringstream errstr;
973 errstr <<
"nonterminal set did not contain the expected nonterminal " << ntit->Str() << std::endl;
974 throw Exception(name, errstr.str(), 1003);
979 std::set<GrammarProduction>::const_iterator gpit, findgpit;
980 for(gpit = finalGpSet.begin(); gpit != finalGpSet.end(); gpit++){
984 if(findgpit == finalGpSet.end()){
985 std::stringstream errstr;
986 errstr <<
"grammar productions set did not contain the expected grammar production " << gpit->Str() << std::endl;
987 throw Exception(name, errstr.str(), 1003);
1001 std::string name =
"Rnpp Grammar 2";
1007 std::vector<Idx> v2;
1009 std::vector<Idx> v3;
1020 vg.push_back(ntPtr);
1028 std::stringstream errstr;
1029 errstr <<
"size of nonterminal set is " << rGr.
Nonterminals().size() <<
", but " << finalNtSet.size() <<
" was expected" << std::endl;
1030 throw Exception(name, errstr.str(), 1003);
1034 std::stringstream errstr;
1035 errstr <<
"size of grammar production set is " << rGr.
GrammarProductions().size() <<
", but " << finalGpSet.size() <<
" was expected" << std::endl;
1036 throw Exception(name, errstr.str(), 1003);
1040 std::set<Nonterminal>::const_iterator ntit, findntit;
1041 for(ntit = finalNtSet.begin(); ntit != finalNtSet.end(); ntit++){
1045 if(findntit == finalNtSet.end()){
1046 std::stringstream errstr;
1047 errstr <<
"nonterminal set did not contain the expected nonterminal " << ntit->Str() << std::endl;
1048 throw Exception(name, errstr.str(), 1003);
1053 std::set<GrammarProduction>::const_iterator gpit, findgpit;
1054 for(gpit = finalGpSet.begin(); gpit != finalGpSet.end(); gpit++){
1058 if(findgpit == finalGpSet.end()){
1059 std::stringstream errstr;
1060 errstr <<
"grammar productions set did not contain the expected grammar production " << gpit->Str() << std::endl;
1061 throw Exception(name, errstr.str(), 1003);
1075 std::string name =
"Rnpp Empty Grammar";
1085 std::stringstream errstr;
1086 errstr <<
"size of nonterminal set is " << rGr.
Nonterminals().size() <<
", but 0 was expected" << std::endl;
1087 throw Exception(name, errstr.str(), 1003);
1091 std::stringstream errstr;
1092 errstr <<
"size of grammar production set is " << rGr.
GrammarProductions().size() <<
", but 0 was expected" << std::endl;
1093 throw Exception(name, errstr.str(), 1003);
1106 std::string name =
"Sp2Lr Terminals";
1116 std::stringstream errstr;
1117 errstr <<
"size of terminal set is " << gr.
Terminals().size() <<
", but "<< g.
Alphabet().Size() <<
" was expected" << std::endl;
1118 throw Exception(name, errstr.str(), 1003);
1121 EventSet::Iterator eventit;
1125 std::stringstream errstr;
1126 errstr <<
"terminal " << g.
EventName(*eventit) <<
" was not found in terminal set" << std::endl;
1127 throw Exception(name, errstr.str(), 1003);
1141 std::string name =
"Sp2Lr Nonterminals";
1150 uint expectedNumberNonterminals = 8;
1153 if(expectedNumberNonterminals != gr.
Nonterminals().size()){
1154 std::stringstream errstr;
1155 errstr <<
"size of nonterminal set is " << gr.
Nonterminals().size() <<
", but "<< expectedNumberNonterminals <<
" was expected" << std::endl;
1156 throw Exception(name, errstr.str(), 1003);
1161 std::stringstream errstr;
1162 errstr <<
"start symbol was " << gr.
StartSymbol().
Str() <<
", but (2, [square]) was expected" << std::endl;
1163 throw Exception(name, errstr.str(), 1003);
1176 std::string name =
"Sp2Lr2 Productions ";
1183 std::vector<Idx> dot, lambda, square;
1220 std::set<GrammarProduction> read;
1223 v.push_back(nt1dot2Ptr);
1227 std::set<GrammarProduction> pop;
1229 v.push_back(tlambdaPtr);
1233 std::set<GrammarProduction> push;
1235 v.push_back(nt2dot2Ptr);
1236 v.push_back(nt2squarePtr);
1239 v.push_back(nt2dotPtr);
1243 std::set<GrammarProduction>
final;
1245 v.push_back(tlambdaPtr);
1248 v.push_back(tlambdaPtr);
1254 std::set<GrammarProduction>::const_iterator gpit;
1256 for(gpit = read.begin(); gpit != read.end(); gpit++){
1257 if(gp.erase(*gpit) == 0){
1258 std::stringstream errstr;
1259 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a read transition, was expected but not found in the grammar" << std::endl;
1260 throw Exception(name, errstr.str(), 1003);
1265 for(gpit = pop.begin(); gpit != pop.end(); gpit++){
1266 if(gp.erase(*gpit) == 0){
1267 std::stringstream errstr;
1268 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a pop transition, was expected but not found in the grammar" << std::endl;
1269 throw Exception(name, errstr.str(), 1003);
1274 for(gpit = push.begin(); gpit != push.end(); gpit++){
1275 if(gp.erase(*gpit) == 0){
1276 std::stringstream errstr;
1277 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a push transition, was expected but not found in the grammar" << std::endl;
1278 throw Exception(name, errstr.str(), 1003);
1283 for(gpit =
final.begin(); gpit !=
final.end(); gpit++){
1284 if(gp.erase(*gpit) == 0){
1285 std::stringstream errstr;
1286 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a final transition, was expected but not found in the grammar" << std::endl;
1287 throw Exception(name, errstr.str(), 1003);
1293 std::stringstream errstr;
1294 errstr <<
"the grammar contained" << gp.size() <<
" more productions than expected" << std::endl;
1295 throw Exception(name, errstr.str(), 1003);
1308 std::string name =
"Test Rup Productions";
1318 std::stringstream errstr;
1320 throw Exception(name, errstr.str(), 1003);
1334 gs.push_back(nt2Ptr);
1338 std::stringstream errstr;
1339 errstr <<
"grammar production (2, [dot], 2) -> a(1, [dot]) was present, but was expected to be deleted" << std::endl;
1340 throw Exception(name, errstr.str(), 1003);
1353 std::string name =
"Test Rup Nonterminals";
1363 std::stringstream errstr;
1364 errstr <<
"size of nonterminals was " << rGr.
Nonterminals().size() <<
", but " << gr.
Nonterminals().size() - 1 <<
" was expected" << std::endl;
1365 throw Exception(name, errstr.str(), 1003);
1373 std::stringstream errstr;
1374 errstr <<
"nonterminal (2, [dot], 2) was present, but was expected to be deleted" << std::endl;
1375 throw Exception(name, errstr.str(), 1003);