pd_alg_opt_test.cpp
Go to the documentation of this file.
1 /** @file pd_alg_opt_test.cpp Unit Tests */
2 
3 
4 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2013 Stefan Jacobi, Sven Schneider, Anne-Kathrin Hess
7 
8 */
9 #include "pd_alg_opt_test.h"
10 
11 namespace faudes {
12 
13 /* *****************
14  * TestRemoveUselessTransitionsNumberOfTransitions
15  * *****************/
17  std::string name = "RemoveUselessTransitions Number of Transitions";
18  TestStart(name);
19 
21 
23 
24  Idx s1 = pd.StateIndex("s1");
25  Idx s2 = pd.StateIndex("s2");
26  Idx square = pd.StackSymbolIndex("square");
27  Idx dot = pd.StackSymbolIndex("dot");
29  Idx a = pd.EventIndex("a");
30  Idx b = pd.EventIndex("b");
31 
32  try{
33 
34  TransSet::Iterator transit;
35  PopPushSet::const_iterator ppit;
36 
37  //number of transitions must be 4
38  if(rPd.TransRelSize() != 4){
39  std::stringstream errstr;
40  errstr << "Number of transitions was expected to be 4, but was " << rPd.TransRelSize() << "." << std::endl;
41  throw Exception(name, errstr.str(), 1003);
42  }
43 
44  //test transition going out from s1
45  for(transit = rPd.TransRelBegin(s1); transit != rPd.TransRelEnd(s1); transit++){
46 
47  //transition with event a must pop square
48  if(transit->Ev == a){
49  for(ppit = rPd.PopPushBegin(*transit); ppit != rPd.PopPushEnd(*transit); ppit++){
50 
51  //transition must pop square
52  if(ppit->first.front() != square){
53  std::stringstream errstr;
54  errstr << "Transition originating at state s1 was expected to pop square, but popped " << rPd.StackSymbolName(ppit->first.front()) << "." << std::endl;
55  throw Exception(name, errstr.str(), 1003);
56  }
57  }
58  }
59 
60  //transition with event b must pop square
61  if(transit->Ev == b){
62  for(ppit = rPd.PopPushBegin(*transit); ppit != rPd.PopPushEnd(*transit); ppit++){
63 
64  //transition must pop square
65  if(ppit->first.front() != square){
66  std::stringstream errstr;
67  errstr << "Transition originating at state s1 was expected to pop square, but popped " << rPd.StackSymbolName(ppit->first.front()) << "." << std::endl;
68  throw Exception(name, errstr.str(), 1003);
69  }
70  }
71  }
72  }
73 
74  //test transitions going out from s2
75  for(transit = rPd.TransRelBegin(s2); transit != rPd.TransRelEnd(s2); transit++){
76 
77  //transition with event a must pop dot
78  if(transit->Ev == a){
79  for(ppit = rPd.PopPushBegin(*transit); ppit != rPd.PopPushEnd(*transit); ppit++){
80 
81  //transition must pop dot
82  if(ppit->first.front() != dot){
83  std::stringstream errstr;
84  errstr << "Transition originating at state s2 with event a was expected to pop dot, but popped " << rPd.StackSymbolName(ppit->first.front()) << "." << std::endl;
85  throw Exception(name, errstr.str(), 1003);
86  }
87  }
88  }
89  //transition with event b must pop lambda
90  if(transit->Ev == b){
91  for(ppit = rPd.PopPushBegin(*transit); ppit != rPd.PopPushEnd(*transit); ppit++){
92 
93  //transition must pop lambda
94  if(ppit->first.front() != lambda){
95  std::stringstream errstr;
96  errstr << "Transition originating at state s2 with event b was expected to pop lambda, but popped " << rPd.StackSymbolName(ppit->first.front()) << "." << std::endl;
97  throw Exception(name, errstr.str(), 1003);
98  }
99  }
100  }
101  }
102  }
103  catch(Exception e){
104  }
105 
106  TestEnd(name);
107 }
108 
109 /* *****************
110  * TestGetPossibleStackTopsFindCorrectOnes
111  * *****************/
113 
114  std::string name = "TestGetPossibleStackTops Find Correct Ones Number";
115  TestStart(name);
116 
118 
119  Idx dot = pd.StackSymbolIndex("dot");
120  Idx heart= pd.StackSymbolIndex("heart");
121  Idx diamond = pd.StackSymbolIndex("diamond");
122  Idx square = pd.StackSymbolIndex("square");
123 
124  Idx s1 = pd.StateIndex("s1");
125  Idx s2 = pd.StateIndex("s2");
126  Idx s3 = pd.StateIndex("s3");
127 
128  StackSymbolSet::Iterator ssit;
129 
130  StackSymbolSet topS1 = GetPossibleStackTops(pd, StateSet(), s1);
131  StackSymbolSet topS2 = GetPossibleStackTops(pd, StateSet(), s2);
132  StackSymbolSet topS3 = GetPossibleStackTops(pd, StateSet(), s3);
133 
134  try{
135 
136  TransSet::Iterator transit;
137  PopPushSet::const_iterator ppit;
138 
139  //test state 1, must contain square and diamond
140  if(topS1.Size() != 2){
141  std::stringstream errstr;
142  errstr << "Number of possible stack top symbols of s1 was expected to be 2, but was " << topS1.Size() << "." << std::endl;
143  throw Exception(name, errstr.str(), 1003);
144  }
145  if(!topS1.Exists(diamond)){
146  std::stringstream errstr;
147  errstr << "Stack symbol diamond was expected to be a possible stack top symbol of s1, but was not." << std::endl;
148  throw Exception(name, errstr.str(), 1003);
149  }
150  if(!topS1.Exists(square)){
151  std::stringstream errstr;
152  errstr << "Stack symbol diamond was expected to be a possible stack top symbol of s1, but was not." << std::endl;
153  throw Exception(name, errstr.str(), 1003);
154  }
155  //test state 2, must contain all symbols
156  if(topS2.Size() != 4){
157  std::stringstream errstr;
158  errstr << "Number of possible stack top symbols of s2 was expected to be 4, but was " << topS2.Size() << "." << std::endl;
159  throw Exception(name, errstr.str(), 1003);
160  }
161  //test state 2, must contain all symbols
162  if(topS3.Size() != 4){
163  std::stringstream errstr;
164  errstr << "Number of possible stack top symbols of s3 was expected to be 4, but was " << topS3.Size() << "." << std::endl;
165  throw Exception(name, errstr.str(), 1003);
166  }
167 
168 
169  }
170  catch(Exception e){
171  }
172 
173  TestEnd(name);
174 }
175 
176 /* *****************
177  * TestRemoveUselessTransitions
178  * *****************/
181 }
182 
183 /* *****************
184  * TestGetPossibleStackTops
185  * *****************/
188 }
189 
190 } // namespace faudes
191 

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen