pd_alg_cc_test.cppGo to the documentation of this file.00001 /** @file pd_alg_cc_test.cpp Unit Tests */ 00002 00003 00004 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes) 00005 00006 Copyright (C) 2013 Stefan Jacobi, Sven Schneider, Anne-Kathrin Hess 00007 00008 */ 00009 #include "pd_alg_cc_test.h" 00010 00011 namespace faudes { 00012 00013 /* ***************** 00014 * TestTransientStates 00015 * *****************/ 00016 void TestTransientStates(){ 00017 std::string name = "Transient States"; 00018 TestStart(name); 00019 00020 PushdownGenerator g1 = TestGenerator6(); 00021 00022 StateSet states = Transient(g1); 00023 00024 try{ 00025 //expected states are s2 and s3 00026 if(!states.Exists(g1.StateIndex("s2")) || !states.Exists(g1.StateIndex("s3"))){ 00027 std::stringstream errstr; 00028 errstr << "States " << g1.StateIndex("s2") << " and " << g1.StateIndex("s3") << " were expected but were not fount in the state set" << std::endl; 00029 throw Exception(name, errstr.str(), 1003); 00030 } 00031 } 00032 catch (Exception e){ 00033 } 00034 00035 TestEnd(name); 00036 } 00037 00038 /* ***************** 00039 * TestTransientStatesEmpty 00040 * *****************/ 00041 void TestTransientStatesEmpty(){ 00042 std::string name = "Transient States Empty"; 00043 TestStart(name); 00044 00045 PushdownGenerator g1 = TestGenerator4(); 00046 00047 StateSet states = Transient(g1); 00048 00049 try{ 00050 //no states are expected 00051 if(!states.Empty()){ 00052 std::stringstream errstr; 00053 errstr << "State set was expected to be empty, but had size " << states.Size() << std::endl; 00054 throw Exception(name, errstr.str(), 1003); 00055 } 00056 } 00057 catch (Exception e){ 00058 } 00059 00060 TestEnd(name); 00061 } 00062 00063 /* ***************** 00064 * TestRnceRemoveEars 00065 * *****************/ 00066 void TestRnceRemoveEars(){ 00067 std::string name = "Rnce Remove Ears"; 00068 TestStart(name); 00069 00070 System s = TestSystem2(); 00071 PushdownGenerator g1 = TestGenerator5(); 00072 00073 PushdownGenerator g2 = Rnce(g1,s); 00074 00075 try{ 00076 //states s31 and s41 must be removed from the generator 00077 if(g2.ExistsState("s31") || g2.ExistsState("s41")){ 00078 std::stringstream errstr; 00079 errstr << "States s31 and s41 were expected to be deleted, but at least one of them was found in the state set" << std::endl; 00080 throw Exception(name, errstr.str(), 1003); 00081 } 00082 //only 6 states must be left in the generator 00083 if(g2.States().Size() != 6){ 00084 std::stringstream errstr; 00085 errstr << "6 states were expected in the generator, but " << g2.States().Size() << " were found" << std::endl; 00086 throw Exception(name, errstr.str(), 1003); 00087 } 00088 } 00089 catch (Exception e){ 00090 } 00091 00092 TestEnd(name); 00093 } 00094 00095 /* ***************** 00096 * TestIntersectEventsAll 00097 * *****************/ 00098 void TestIntersectEventsAll(){ 00099 00100 std::string name = "Intersect Events All"; 00101 TestStart(name); 00102 00103 System s; 00104 PushdownGenerator g1; 00105 00106 //build two event sets to test every configuration of (un)controllable 00107 //and (un)observable at least once 00108 s.InsEvent("a"); g1.InsEvent("a"); 00109 s.InsControllableEvent("b"); s.ClrObservable("b"); g1.InsControllableEvent("b"); g1.ClrObservable("b"); 00110 s.InsControllableEvent("c"); g1.InsControllableEvent("c"); 00111 s.InsUnobservableEvent("d"); g1.InsUnobservableEvent("d"); 00112 s.InsEvent("e"); g1.InsUnobservableEvent("e"); 00113 s.InsEvent("f"); g1.InsControllableEvent("f"); g1.ClrObservable("f"); 00114 s.InsEvent("g"); g1.InsControllableEvent("g"); 00115 s.InsControllableEvent("h"); s.ClrObservable("h"); g1.InsUnobservableEvent("h"); 00116 s.InsControllableEvent("i"); s.ClrObservable("i"); g1.InsControllableEvent("i"); 00117 s.InsControllableEvent("j"); g1.InsUnobservableEvent("j"); 00118 00119 PushdownGenerator g2; 00120 IntersectEvents(s, g1, g2); 00121 00122 try{ 00123 //resulting size of events has to be 4 (containing a, b, c and d) 00124 if(g2.Alphabet().Size() != 4){ 00125 std::stringstream errstr; 00126 errstr << "size of event set is " << g2.Alphabet().Size() << " ("; 00127 EventSet::Iterator evit; 00128 for(evit = g2.AlphabetBegin(); evit != g2.AlphabetEnd(); evit++){ 00129 if(evit == g2.AlphabetBegin()){ 00130 errstr << g2.EventName(*evit); 00131 } 00132 else{ 00133 errstr << ", " << g2.EventName(*evit); 00134 } 00135 } 00136 errstr << "), but 4 (a, b, c, d) was expected" << std::endl; 00137 throw Exception(name, errstr.str(), 1003); 00138 } 00139 //a must be observable and must not be controllable 00140 if(!(!g2.Controllable("a") && g2.Observable("a"))){ 00141 std::stringstream errstr; 00142 errstr << "event a must not be controllable and must be observable, but controllable: " << g2.Controllable("a") << " and observable: " << g2.Observable("a")<< std::endl; 00143 throw Exception(name, errstr.str(), 1003); 00144 } 00145 //b must not be observable and must be controllable 00146 if(!(g2.Controllable("b") && !g2.Observable("b"))){ 00147 std::stringstream errstr; 00148 errstr << "event b must be controllable and must not be observable, but controllable: " << g2.Controllable("b") << " and observable: " << g2.Observable("b")<< std::endl; 00149 throw Exception(name, errstr.str(), 1003); 00150 } 00151 //c must be observable and must be controllable 00152 if(!(g2.Controllable("c") && g2.Observable("c"))){ 00153 std::stringstream errstr; 00154 errstr << "event c must be controllable and must be observable, but controllable: " << g2.Controllable("c") << " and observable: " << g2.Observable("c")<< std::endl; 00155 throw Exception(name, errstr.str(), 1003); 00156 } 00157 //d must not be observable and must not be controllable 00158 if(!(!g2.Controllable("d") && !g2.Observable("d"))){ 00159 std::stringstream errstr; 00160 errstr << "event d must not be controllable and must not be observable, but controllable: " << g2.Controllable("d") << " and observable: " << g2.Observable("d")<< std::endl; 00161 throw Exception(name, errstr.str(), 1003); 00162 } 00163 } 00164 catch(Exception e){ 00165 } 00166 00167 TestEnd(name); 00168 } 00169 00170 /* ***************** 00171 * TestTimesStates 00172 * *****************/ 00173 void TestTimesStates(){ 00174 00175 std::string name = "Times States"; 00176 TestStart(name); 00177 00178 System s = TestSystem1(); 00179 PushdownGenerator g1 = TestGenerator2(); 00180 00181 //create expected merge states 00182 std::set< std::vector<Idx> > expectedMergeStateSet; 00183 std::vector<Idx> expectedMergeStates; 00184 StateSet::Iterator sit, g1it, g2it; 00185 for(sit = s.StatesBegin(); sit != s.StatesEnd(); sit++){ 00186 for(g1it = g1.StatesBegin(); g1it != g1.StatesEnd(); g1it++){ 00187 expectedMergeStates.clear(); 00188 expectedMergeStates.push_back(*sit); 00189 expectedMergeStates.push_back(*g1it); 00190 expectedMergeStateSet.insert(expectedMergeStates); 00191 } 00192 } 00193 00194 PushdownGenerator g2 = Times(s,g1); 00195 00196 try{ 00197 //the number of states in g2 must be g2States = sStates*g1States 00198 if(g2.States().Size() != s.States().Size() * g1.States().Size()){ 00199 std::stringstream errstr; 00200 errstr << "number of states incorrect, was " << g2.States().Size() << ", but " << s.States().Size() * g1.States().Size() << " was expected" << std::endl; 00201 throw Exception(name, errstr.str(), 1003); 00202 } 00203 00204 //all elements of the cartesian product of state indices g1States x sStates 00205 //must appear uniquely in the merge states attribute 00206 std::set<std::vector<Idx> >::const_iterator emsit; 00207 for(g2it = g2.StatesBegin(); g2it != g2.StatesEnd(); g2it++){ 00208 00209 //check if the merge attribute is of type MergeStates 00210 const MergeStates* ms = dynamic_cast<const MergeStates*> (g2.StateAttribute(*g2it).Merge()); 00211 if(ms == NULL){ 00212 std::stringstream errstr; 00213 errstr << "MergeStateAnnotation in state " << *g2it << " not set." << std::endl; 00214 throw Exception(name, errstr.str(), 1003); 00215 } 00216 00217 emsit = expectedMergeStateSet.find(ms->States()); 00218 //check if the contained state indices match the expected indices 00219 if(emsit == expectedMergeStateSet.end()){ 00220 std::stringstream errstr; 00221 errstr << "mergeStates attribute of state " << *g2it << " was ("; 00222 std::vector<Idx>::const_iterator vit; 00223 for(vit = ms->States().begin(); vit != ms->States().end(); vit++){ 00224 if(vit == ms->States().begin()){ 00225 errstr << *vit; 00226 } 00227 else{ 00228 errstr << ", " << *vit; 00229 } 00230 } 00231 errstr << "), but was not expected. it may have already occured or not been expected at all" << std::endl; 00232 throw Exception(name, errstr.str(), 1003); 00233 } 00234 //if indices match, delete the expected element because it is only expected once 00235 expectedMergeStateSet.erase(ms->States()); 00236 } 00237 } 00238 catch(Exception e){ 00239 } 00240 00241 TestEnd(name); 00242 } 00243 00244 /* ***************** 00245 * TestTimesStackSymbols 00246 * *****************/ 00247 void TestTimesStackSymbols(){ 00248 std::string name = "Times Stack Symbols"; 00249 TestStart(name); 00250 00251 System s = TestSystem1(); 00252 PushdownGenerator g1 = TestGenerator2(); 00253 00254 PushdownGenerator g2 = Times(s,g1); 00255 00256 try{ 00257 StackSymbolSet::Iterator g1ssit, g2ssit; 00258 //ever stack symbol in g1 must be in g2 00259 for(g1ssit = g1.StackSymbolsBegin(); g1ssit != g1.StackSymbolsEnd(); g1ssit++){ 00260 g2ssit = g2.StackSymbols().Find(g1.StackSymbolName(*g1ssit)); 00261 if(g2ssit == g2.StackSymbols().End()){ 00262 std::stringstream errstr; 00263 errstr << "stack symbol " << g1.StackSymbolName(*g1ssit) << " was expected but not found" << std::endl; 00264 throw Exception(name, errstr.str(), 1003); 00265 } 00266 } 00267 00268 //the number of stack symbols in g2 must be the number of stack symbols in g1 00269 if(g2.StackSymbols().Size() != g1.StackSymbols().Size()){ 00270 std::stringstream errstr; 00271 errstr << "number of stack symbols incorrect, was " << g2.StackSymbols().Size() << ", but " << g1.StackSymbols().Size() << " was expected" << std::endl; 00272 throw Exception(name, errstr.str(), 1003); 00273 } 00274 00275 //the stack bottoms must match 00276 if(g2.StackSymbolObj(g2.StackBottom()) != g1.StackSymbolObj(g1.StackBottom())){ 00277 std::stringstream errstr; 00278 errstr << "stack bottom symbol incorrect, was " << g2.StackSymbolName(g2.StackBottom()) << ", but " << g1.StackSymbolName(g1.StackBottom()) << " was expected" << std::endl; 00279 throw Exception(name, errstr.str(), 1003); 00280 } 00281 } 00282 catch(Exception e){ 00283 } 00284 00285 TestEnd(name); 00286 } 00287 00288 /* ***************** 00289 * TestTimesTransitions 00290 * *****************/ 00291 void TestTimesTransitions(){ 00292 std::string name = "Times Transitions"; 00293 TestStart(name); 00294 00295 System s = TestSystem1(); 00296 PushdownGenerator g1 = TestGenerator2(); 00297 00298 TransSet::Iterator g1Transit; 00299 //determine number of expected lambda-read transitions in resulting generator 00300 uint expectedLambdaReads = 0; 00301 for(g1Transit = g1.TransRelBegin(); g1Transit != g1.TransRelEnd(); g1Transit++){ 00302 if(g1.EventName(g1Transit->Ev).compare(FAUDES_PD_LAMBDA) == 0){ 00303 expectedLambdaReads += s.States().Size() * g1.PopPush(*g1Transit).size(); 00304 } 00305 } 00306 00307 TransSet::Iterator sTransit; 00308 //determine number of expected transtitions (without lambda read) 00309 uint expectedTransitions = 0; 00310 for(g1Transit = g1.TransRelBegin(); g1Transit != g1.TransRelEnd(); g1Transit++){ 00311 for(sTransit = s.TransRelBegin(); sTransit != s.TransRelEnd(); sTransit++){ 00312 if(g1.EventName(g1Transit->Ev).compare(s.EventName(sTransit->Ev)) == 0){ 00313 expectedTransitions += g1.PopPush(*g1Transit).size(); 00314 } 00315 } 00316 } 00317 00318 PushdownGenerator g2 = Times(s,g1); 00319 00320 try{ 00321 TransSet::Iterator g2Transit; 00322 //for every lambda-read transition in g1 there must be a lambda read transition 00323 //for every state in s 00324 uint lambdaReads = 0; 00325 for(g2Transit = g2.TransRelBegin(); g2Transit != g2.TransRelEnd(); g2Transit++){ 00326 if(g2.EventName(g2Transit->Ev).compare(FAUDES_PD_LAMBDA) == 0){ 00327 lambdaReads += g2.PopPush(*g2Transit).size(); 00328 } 00329 } 00330 if(lambdaReads != expectedLambdaReads){ 00331 std::stringstream errstr; 00332 errstr << "number of lambda read transition was " << lambdaReads << ", but " << expectedLambdaReads << " was expected" << std::endl; 00333 throw Exception(name, errstr.str(), 1003); 00334 } 00335 00336 //the total number of transitions should be 00337 //expectedLambdaReads + expectedTransitions 00338 if(lambdaReads + expectedTransitions != g2.TransRel().Size()){ 00339 std::stringstream errstr; 00340 errstr << "total number of transitions was " << g2.TransRel().Size() << ", but " << expectedLambdaReads + expectedTransitions << " was expected" << std::endl; 00341 throw Exception(name, errstr.str(), 1003); 00342 } 00343 } 00344 catch(Exception e){ 00345 } 00346 00347 TestEnd(name); 00348 } 00349 00350 /* ***************** 00351 * TestSplitStackSymbols 00352 * *****************/ 00353 void TestSplitStackSymbols(){ 00354 std::string name = "Split Stack Symbols"; 00355 TestStart(name); 00356 00357 PushdownGenerator g1 = TestGenerator3(); 00358 00359 PushdownGenerator g2 = Split(g1); 00360 00361 try{ 00362 //the stack bottom symbol must not be changed 00363 if(g2.StackSymbolObj(g2.StackBottom()) != g1.StackSymbolObj(g1.StackBottom())){ 00364 std::stringstream errstr; 00365 errstr << "stack bottom symbol was " << g2.StackSymbolName(g2.StackBottom()) << ", but " << g1.StackSymbolName(g1.StackBottom()) << " was expected" << std::endl; 00366 throw Exception(name, errstr.str(), 1003); 00367 } 00368 00369 StackSymbolSet::Iterator ssit; 00370 //all stack symbols of the old generator must found in the new generator 00371 for(ssit = g1.StackSymbolsBegin(); ssit != g1.StackSymbolsEnd(); ssit++){ 00372 if(g2.StackSymbols().Exists(g1.StackSymbolName(*ssit)) == 0){ 00373 std::stringstream errstr; 00374 errstr << "stack symbol " << g1.StackSymbolName(*ssit) << " was expected in the stack symbol set but not found" << std::endl; 00375 throw Exception(name, errstr.str(), 1003); 00376 } 00377 } 00378 } 00379 catch(Exception e){ 00380 } 00381 00382 TestEnd(name); 00383 } 00384 00385 /* ***************** 00386 * TestSplitStates 00387 * *****************/ 00388 void TestSplitStates(){ 00389 std::string name = "Split States"; 00390 TestStart(name); 00391 00392 PushdownGenerator g1 = TestGenerator3(); 00393 00394 //set of split state attributes that are expected 00395 std::set<std::pair<Idx,Idx> > splitStateSet; 00396 StateSet::Iterator stateit; 00397 StackSymbolSet::Iterator ssit; 00398 for(stateit = g1.StatesBegin(); stateit != g1.StatesEnd(); stateit++){ 00399 00400 //insert expected head 00401 splitStateSet.insert(std::make_pair(*stateit, 0)); 00402 for(ssit = g1.StackSymbolsBegin(); ssit != g1.StackSymbolsEnd(); ssit++){ 00403 00404 if(!g1.IsStackSymbolLambda(*ssit)){ 00405 splitStateSet.insert(std::make_pair(*stateit, *ssit)); 00406 } 00407 } 00408 } 00409 00410 PushdownGenerator g2 = Split(g1); 00411 00412 try{ 00413 00414 for(stateit = g2.StatesBegin(); stateit != g2.StatesEnd(); stateit++){ 00415 00416 const MergeStateSplit* mss = dynamic_cast<const MergeStateSplit*>(g2.StateAttribute(*stateit).Merge()); 00417 00418 //test if MergeStateSplit was set 00419 if(mss == NULL){ 00420 std::stringstream errstr; 00421 errstr << "MergeStateSplit attribute not set for state " << *stateit << std::endl; 00422 throw Exception(name, errstr.str(), 1003); 00423 } 00424 00425 //test if state was expected 00426 if(splitStateSet.erase(std::make_pair(mss->State(), mss->Symbol())) == 0){ 00427 std::stringstream errstr; 00428 if(!mss->IsHead()){ 00429 errstr << "Ear state with merge attribute (state: " << mss->State() << ", stack symbol: " << g2.StackSymbolName(mss->Symbol()) << ") found, but was not expected." << std::endl; 00430 } 00431 00432 else{ 00433 errstr << "Head state with merge attribute (state: " << mss->State() << ") found, but was not expected." << std::endl; 00434 } 00435 throw Exception(name, errstr.str(), 1003); 00436 } 00437 } 00438 00439 //test if any expected states are left 00440 if(splitStateSet.size() != 0){ 00441 std::stringstream errstr; 00442 errstr << splitStateSet.size() << " states are missing from the generator: \n"; 00443 00444 std::set<std::pair<Idx,Idx> >::iterator it; 00445 for(it = splitStateSet.begin(); it != splitStateSet.end(); it++){ 00446 if(it->second != 0){ 00447 errstr << "ear state with merge attribute (state: " << it->first << ", stack symbol: " << g2.StackSymbolName(it->second) << ")\n"; 00448 } 00449 else{ 00450 errstr << "head state with merge attribute (state: " << it->first << ")\n"; 00451 } 00452 } 00453 errstr << std::endl; 00454 throw Exception(name, errstr.str(), 1003); 00455 } 00456 } 00457 catch(Exception e){ 00458 } 00459 00460 TestEnd(name); 00461 } 00462 00463 /* ***************** 00464 * TestSplitTransitionsHeadToEar 00465 * *****************/ 00466 void TestSplitTransitionsHeadToEar(){ 00467 std::string name = "Split Transitions Head To Ear"; 00468 TestStart(name); 00469 00470 PushdownGenerator g1 = TestGenerator3(); 00471 00472 PushdownGenerator g2 = Split(g1); 00473 00474 try{ 00475 StateSet::Iterator stateit; 00476 TransSet::Iterator transit; 00477 PopPushSet::const_iterator ppit; 00478 //look at all states 00479 for(stateit = g2.StatesBegin(); stateit != g2.StatesEnd(); stateit++){ 00480 00481 const MergeStateSplit* mss1 = dynamic_cast<const MergeStateSplit*>(g2.StateAttribute(*stateit).Merge()); 00482 00483 //if the current state is a head 00484 if(mss1->IsHead()){ 00485 00486 //look at all transitions starting here 00487 for(transit = g2.TransRelBegin(*stateit); transit != g2.TransRelEnd(*stateit); transit++){ 00488 for(ppit = g2.PopPushBegin(*transit); ppit != g2.PopPushEnd(*transit); ppit++){ 00489 00490 const MergeStateSplit* mss2 = dynamic_cast<const MergeStateSplit*>(g2.StateAttribute(transit->X2).Merge()); 00491 00492 //the end state of the transition must be an ear (i. e. not a head) 00493 if(mss2->IsHead()){ 00494 std::stringstream errstr; 00495 errstr << "Transition from head to head found (from " << *stateit << " to " << transit->X2 << ") found, but from head to ear was expected." << std::endl; 00496 throw Exception(name, errstr.str(), 1003); 00497 } 00498 00499 //pop and push size must be one 00500 if(ppit->first.size() != 1 || ppit->second.size() != 1){ 00501 std::stringstream errstr; 00502 errstr << "Pop size was " << ppit->first.size() << " and push size was " << ppit->second.size() << " at transition from head state " << transit->X1 << " to ear state " << transit->X2 << ", but size 1 was expected for both." << std::endl; 00503 throw Exception(name, errstr.str(), 1003); 00504 } 00505 00506 //the ear's associated stack symbol must be popped and pushed 00507 if(mss2->Symbol() != ppit->first.front() || mss2->Symbol() != ppit->second.front()){ 00508 std::stringstream errstr; 00509 errstr << "Transition from head state " << transit->X1 << " to ear state " << transit->X2 << "has pop stack symbol idx" << ppit->first.front() << " and push stack symbol idx" << ppit->second.front() << ", but expected was the stack symbol idx" << mss2->Symbol() << ", because it is associated with the ear." << std::endl; 00510 throw Exception(name, errstr.str(), 1003); 00511 } 00512 } 00513 } 00514 } 00515 } 00516 } 00517 catch(Exception e){ 00518 } 00519 00520 TestEnd(name); 00521 } 00522 00523 /* ***************** 00524 * TestSplitTransitionsEarToHead 00525 * *****************/ 00526 void TestSplitTransitionsEarToHead(){ 00527 std::string name = "Split Transitions Ear To Head"; 00528 TestStart(name); 00529 00530 PushdownGenerator g1 = TestGenerator3(); 00531 00532 PushdownGenerator g2 = Split(g1); 00533 00534 try{ 00535 StateSet::Iterator stateit; 00536 TransSet::Iterator transit; 00537 PopPushSet::const_iterator ppit; 00538 //look at all states 00539 for(stateit = g2.StatesBegin(); stateit != g2.StatesEnd(); stateit++){ 00540 00541 const MergeStateSplit* mss1 = dynamic_cast<const MergeStateSplit*>(g2.StateAttribute(*stateit).Merge()); 00542 00543 //if the current state is an ear 00544 if(!mss1->IsHead()){ 00545 00546 //look at all transitions starting here 00547 for(transit = g2.TransRelBegin(*stateit); transit != g2.TransRelEnd(*stateit); transit++){ 00548 for(ppit = g2.PopPushBegin(*transit); ppit != g2.PopPushEnd(*transit); ppit++){ 00549 00550 const MergeStateSplit* mss2 = dynamic_cast<const MergeStateSplit*>(g2.StateAttribute(transit->X2).Merge()); 00551 00552 //the end state of the transition must be a head 00553 if(!mss2->IsHead()){ 00554 std::stringstream errstr; 00555 errstr << "Transition from ear to ear found (from " << *stateit << " to " << transit->X2 << ") found, but from ear to head was expected." << std::endl; 00556 throw Exception(name, errstr.str(), 1003); 00557 } 00558 00559 //pop size must be one 00560 if(ppit->first.size() != 1){ 00561 std::stringstream errstr; 00562 errstr << "Pop size was " << ppit->first.size() << " but size 1 was expected." << std::endl; 00563 throw Exception(name, errstr.str(), 1003); 00564 } 00565 00566 //the ear's associated stack symbol must be popped 00567 if(mss1->Symbol() != ppit->first.front()){ 00568 std::stringstream errstr; 00569 errstr << "Transition from ear state " << transit->X1 << " to head state " << transit->X2 << "has pop stack symbol idx " << ppit->first.front() << ", but " << mss1->Symbol() << " was expected, because it is associated with the ear." << std::endl; 00570 throw Exception(name, errstr.str(), 1003); 00571 } 00572 } 00573 } 00574 } 00575 } 00576 } 00577 catch(Exception e){ 00578 } 00579 00580 TestEnd(name); 00581 } 00582 00583 /* ***************** 00584 * TestTsUnreachable 00585 * *****************/ 00586 void TestTsUnreachable(){ 00587 std::string name = "Ts Unreachable"; 00588 TestStart(name); 00589 00590 PushdownGenerator pd = TestGenerator12(); 00591 00592 Idx s3Idx = pd.StateIndex("s3"); 00593 Idx s4Idx = pd.StateIndex("s4"); 00594 bool s3Reachable = Ts(pd, s3Idx); 00595 bool s4Reachable = Ts(pd, s4Idx); 00596 00597 try{ 00598 00599 //both s3 and s4 must not be reachable 00600 if(s3Reachable){ 00601 std::stringstream errstr; 00602 errstr << "State s3 was expected to be not reachable, but was reachable." << std::endl; 00603 throw Exception(name, errstr.str(), 1003); 00604 } 00605 if(s4Reachable){ 00606 std::stringstream errstr; 00607 errstr << "State s4 was expected to be not reachable, but was reachable." << std::endl; 00608 throw Exception(name, errstr.str(), 1003); 00609 } 00610 } 00611 catch(Exception e){ 00612 } 00613 00614 TestEnd(name); 00615 } 00616 00617 /* ***************** 00618 * TestTeReachable 00619 * *****************/ 00620 void TestTeReachable(){ 00621 std::string name = "Te Reachable"; 00622 TestStart(name); 00623 00624 PushdownGenerator pd = TestGenerator16(); 00625 00626 std::vector<StackSymbol> vSquare; 00627 vSquare.push_back(StackSymbol("square")); 00628 std::vector<StackSymbol> vDot; 00629 vDot.push_back(StackSymbol("dot")); 00630 std::vector<StackSymbol> vDotSquare; 00631 vDotSquare.push_back(StackSymbol("dot")); 00632 vDotSquare.push_back(StackSymbol("square")); 00633 00634 Transition trans1 = *pd.FindTransition("s1","a","s1"); 00635 Transition trans2 = *pd.FindTransition("s2","b","s3"); 00636 00637 bool trans1Reachable = Te(pd, trans1, pd.StackSymbolsToIndices(vDot), pd.StackSymbolsToIndices(vDot)); 00638 bool trans2Reachable = Te(pd, trans2, pd.StackSymbolsToIndices(vSquare), pd.StackSymbolsToIndices(vDotSquare)); 00639 00640 try{ 00641 00642 //both trans1 and trans2 must be reachable 00643 if(!trans1Reachable){ 00644 std::stringstream errstr; 00645 errstr << "Transitions from s1 to s1 with a/dot/dot was expected to be reachable, but was not." << std::endl; 00646 throw Exception(name, errstr.str(), 1003); 00647 } 00648 if(!trans2Reachable){ 00649 std::stringstream errstr; 00650 errstr << "Transitions from s2 to s3 with b/square/dotsquare was expected to be reachable, but was not." << std::endl; 00651 throw Exception(name, errstr.str(), 1003); 00652 } 00653 } 00654 catch(Exception e){ 00655 } 00656 00657 TestEnd(name); 00658 } 00659 00660 /* ***************** 00661 * TestTeUnreachable 00662 * *****************/ 00663 void TestTeUnreachable(){ 00664 std::string name = "Te Unreachable"; 00665 TestStart(name); 00666 00667 PushdownGenerator pd = TestGenerator15(); 00668 00669 std::vector<StackSymbol> vSquare; 00670 vSquare.push_back(StackSymbol("square")); 00671 std::vector<StackSymbol> vDot; 00672 vDot.push_back(StackSymbol("dot")); 00673 std::vector<StackSymbol> vDotSquare; 00674 vDotSquare.push_back(StackSymbol("dot")); 00675 vDotSquare.push_back(StackSymbol("square")); 00676 00677 Transition trans1 = *pd.FindTransition("s1","a","s1"); 00678 Transition trans2 = *pd.FindTransition("s2","b","s3"); 00679 00680 bool trans1Reachable = Te(pd, trans1, pd.StackSymbolsToIndices(vDot), pd.StackSymbolsToIndices(vDot)); 00681 bool trans2Reachable = Te(pd, trans2, pd.StackSymbolsToIndices(vSquare), pd.StackSymbolsToIndices(vDotSquare)); 00682 00683 try{ 00684 00685 //both trans1 and trans2 must not be reachable 00686 if(trans1Reachable){ 00687 std::stringstream errstr; 00688 errstr << "Transitions from s1 to s1 with a/dot/dot was expected to be not reachable, but was reachable." << std::endl; 00689 throw Exception(name, errstr.str(), 1003); 00690 } 00691 if(trans2Reachable){ 00692 std::stringstream errstr; 00693 errstr << "Transitions from s2 to s3 with b/square/dotsquare was expected to be not reachable, but was reachable." << std::endl; 00694 throw Exception(name, errstr.str(), 1003); 00695 } 00696 } 00697 catch(Exception e){ 00698 } 00699 00700 TestEnd(name); 00701 } 00702 00703 /* ***************** 00704 * TestRulsRemoveStates 00705 * *****************/ 00706 void TestRulsRemoveStates(){ 00707 std::string name = "Ruls Remove States"; 00708 TestStart(name); 00709 00710 PushdownGenerator pd = TestGenerator14(); 00711 00712 PushdownGenerator rPd = Ruls(pd); 00713 00714 try{ 00715 00716 //both s1d and s2s must be deleted 00717 if(rPd.ExistsState("s1d")){ 00718 std::stringstream errstr; 00719 errstr << "State s1d was expected to be deleted, but was not." << std::endl; 00720 throw Exception(name, errstr.str(), 1003); 00721 } 00722 if(rPd.ExistsState("s2s")){ 00723 std::stringstream errstr; 00724 errstr << "State s2s was expected to be deleted, but was not." << std::endl; 00725 throw Exception(name, errstr.str(), 1003); 00726 } 00727 00728 //there must be 4 states remaining 00729 if(rPd.Size() != 4){ 00730 std::stringstream errstr; 00731 errstr << "Number of remaining states was expected to be 4, but was "<< rPd.Size() << "." << std::endl; 00732 throw Exception(name, errstr.str(), 1003); 00733 } 00734 } 00735 catch(Exception e){ 00736 } 00737 00738 TestEnd(name); 00739 } 00740 00741 /* ***************** 00742 * TestAcAccessible 00743 * *****************/ 00744 void TestAcAccessible(){ 00745 std::string name = "Ac Accessible"; 00746 TestStart(name); 00747 00748 PushdownGenerator pd = TestGenerator17(); 00749 00750 PushdownGenerator rPd; 00751 PushdownAccessible(pd,rPd); 00752 00753 try{ 00754 00755 //states s1, s2 and s4 must remain 00756 if(!rPd.ExistsState("s1")){ 00757 std::stringstream errstr; 00758 errstr << "State s1 was expected to exist, but did not." << std::endl; 00759 throw Exception(name, errstr.str(), 1003); 00760 } 00761 if(!rPd.ExistsState("s2")){ 00762 std::stringstream errstr; 00763 errstr << "State s2 was expected to exist, but did not." << std::endl; 00764 throw Exception(name, errstr.str(), 1003); 00765 } 00766 if(!rPd.ExistsState("s4")){ 00767 std::stringstream errstr; 00768 errstr << "State s4 was expected to exist, but did not." << std::endl; 00769 throw Exception(name, errstr.str(), 1003); 00770 } 00771 00772 //there must be 3 states remaining 00773 if(rPd.Size() != 3){ 00774 std::stringstream errstr; 00775 errstr << "Number of remaining states was expected to be 3, but was "<< rPd.Size() << "." << std::endl; 00776 throw Exception(name, errstr.str(), 1003); 00777 } 00778 00779 //there must be 2 transitions remaining 00780 if(rPd.TransRelSize() != 2){ 00781 std::stringstream errstr; 00782 errstr << "Number of remaining transitions was expected to be 2, but was "<< rPd.TransRelSize() << "." << std::endl; 00783 throw Exception(name, errstr.str(), 1003); 00784 } 00785 } 00786 catch(Exception e){ 00787 } 00788 00789 TestEnd(name); 00790 } 00791 00792 /* ***************** 00793 * TestTransient 00794 * *****************/ 00795 void TestTransient(){ 00796 00797 TestTransientStates(); 00798 TestTransientStatesEmpty(); 00799 } 00800 00801 /* ***************** 00802 * TestRnce 00803 * *****************/ 00804 void TestRnce(){ 00805 00806 TestRnceRemoveEars(); 00807 } 00808 00809 /* ***************** 00810 * TestTimes 00811 * *****************/ 00812 void TestTimes(){ 00813 00814 TestIntersectEvents(); 00815 TestTimesStates(); 00816 TestTimesStackSymbols(); 00817 TestTimesTransitions(); 00818 } 00819 00820 /* ***************** 00821 * TestIntersectEvents 00822 * *****************/ 00823 void TestIntersectEvents(){ 00824 TestIntersectEventsAll(); 00825 } 00826 00827 /* ***************** 00828 * TestSplit 00829 * *****************/ 00830 void TestSplit(){ 00831 TestSplitStackSymbols(); 00832 TestSplitStates(); 00833 TestSplitTransitionsHeadToEar(); 00834 TestSplitTransitionsEarToHead(); 00835 } 00836 00837 /* ***************** 00838 * TestNonblock 00839 * *****************/ 00840 void TestNonblock(){ 00841 PushdownGenerator pd = TestGenerator9(); 00842 //pd.Write(); 00843 //PushdownGenerator rPd = Nonblock(pd); 00844 00845 // LangK test(rPd); 00846 // test.FindLangK(100); 00847 // test.PrintWords(); 00848 //rPd.Write(); 00849 } 00850 00851 /* ***************** 00852 * TestTs 00853 * *****************/ 00854 void TestTs(){ 00855 TestTsUnreachable(); 00856 } 00857 00858 /* ***************** 00859 * TestTe 00860 * *****************/ 00861 void TestTe(){ 00862 TestTeReachable(); 00863 TestTeUnreachable(); 00864 } 00865 00866 /* ***************** 00867 * TestRuls 00868 * *****************/ 00869 void TestRuls(){ 00870 TestRulsRemoveStates(); 00871 } 00872 00873 /* ***************** 00874 * TestAc 00875 * *****************/ 00876 void TestAc(){ 00877 TestAcAccessible(); 00878 } 00879 } // namespace faudes 00880 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |