14 if(!rc) { |
14 if(!rc) { |
15 cout << "Test failed!" << endl; |
15 cout << "Test failed!" << endl; |
16 } |
16 } |
17 } |
17 } |
18 |
18 |
|
19 #ifdef DEBUG |
|
20 const bool debug = true; |
|
21 #else |
|
22 const bool debug = false; |
|
23 #endif |
|
24 |
|
25 |
19 int main() { |
26 int main() { |
20 |
27 |
21 typedef ListGraph::Node Node; |
28 try { |
22 typedef ListGraph::Edge Edge; |
|
23 |
29 |
24 ListGraph G; |
30 typedef ListGraph::Node Node; |
|
31 typedef ListGraph::Edge Edge; |
25 |
32 |
26 Node s=G.addNode(); |
33 ListGraph G; |
27 Node v1=G.addNode(); |
34 |
28 Node v2=G.addNode(); |
35 Node s=G.addNode(); |
29 Node v3=G.addNode(); |
36 Node v1=G.addNode(); |
30 Node v4=G.addNode(); |
37 Node v2=G.addNode(); |
31 Node t=G.addNode(); |
38 Node v3=G.addNode(); |
|
39 Node v4=G.addNode(); |
|
40 Node t=G.addNode(); |
32 |
41 |
33 Edge e1 = G.addEdge(s, v1); |
42 Edge e1 = G.addEdge(s, v1); |
34 Edge e2 = G.addEdge(s, v2); |
43 Edge e2 = G.addEdge(s, v2); |
35 Edge e3 = G.addEdge(v1, v2); |
44 Edge e3 = G.addEdge(v1, v2); |
36 Edge e4 = G.addEdge(v2, v1); |
45 Edge e4 = G.addEdge(v2, v1); |
37 Edge e5 = G.addEdge(v1, v3); |
46 Edge e5 = G.addEdge(v1, v3); |
38 Edge e6 = G.addEdge(v3, v2); |
47 Edge e6 = G.addEdge(v3, v2); |
39 Edge e7 = G.addEdge(v2, v4); |
48 Edge e7 = G.addEdge(v2, v4); |
40 Edge e8 = G.addEdge(v4, v3); |
49 Edge e8 = G.addEdge(v4, v3); |
41 Edge e9 = G.addEdge(v3, t); |
50 Edge e9 = G.addEdge(v3, t); |
42 Edge e10 = G.addEdge(v4, t); |
51 Edge e10 = G.addEdge(v4, t); |
43 |
52 |
44 bool rc; |
53 bool rc; |
45 |
54 |
46 { |
55 { |
47 cout << "DynamicPath tesztelese...\n"; |
56 cout << "\n\n\nDirPath tesztelese...\n"; |
48 |
57 |
49 cout << "Ures path letrehozasa" << endl; |
|
50 typedef DynamicPath<ListGraph> LPath; |
|
51 LPath P(G); |
|
52 |
58 |
53 cout << "P.length() == " << P.length() << endl; |
59 cout << "Ures path letrehozasa" << endl; |
54 check(P.length() == 0); |
60 typedef DirPath<ListGraph> DPath; |
|
61 DPath P(G); |
55 |
62 |
56 cout << "P.from() valid? " << G.valid(P.from()) << endl; |
63 cout << "P.length() == " << P.length() << endl; |
57 check(! G.valid(P.from())); |
64 check(P.length() == 0); |
58 |
65 |
59 cout << "Hozzaadunk ket elet..." << endl; |
66 cout << "P.from() valid? " << G.valid(P.from()) << endl; |
60 check(P.pushBack(e1)); |
67 check(! G.valid(P.from())); |
61 check(P.pushBack(e3)); |
|
62 cout << "P.length() == " << P.length() << endl; |
|
63 check(P.length() == 2); |
|
64 |
68 |
65 cout << "P.from() valid? " << G.valid(P.from()) << endl; |
69 { |
66 check(G.valid(P.from())); |
70 cout << "Builder objektum letrehozasa" << endl; |
67 |
71 DPath::Builder B(P); |
68 cout << "P.from()==s ? " << (P.from()==s) << endl; |
|
69 check(P.from() == s); |
|
70 |
72 |
71 cout << "Hozzaadunk egy nem illeszkedo elt." << endl; |
73 cout << "Hozzaadunk az elejehez ket elet..." << endl; |
72 rc = P.pushBack(e8); |
74 B.pushFront(e6); |
73 cout << "Sukerult: " << rc << endl; |
75 B.pushFront(e5); |
74 check(!rc); |
76 cout << "P.length() == " << P.length() << endl; |
|
77 check(P.length() == 0); |
|
78 |
|
79 cout << "Commitolunk..." << endl; |
|
80 B.commit(); |
75 |
81 |
76 cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl; |
82 cout << "P.length() == " << P.length() << endl; |
77 check(P.pushBack(e6)); |
83 check(P.length() == 2); |
78 check(P.pushBack(e8)); |
84 cout << "P.from() valid? " << G.valid(P.from()) << endl; |
79 check(P.pushBack(e10)); |
85 check(G.valid(P.from())); |
|
86 cout << "P.from()==v1 ? " << (P.from()==v1) << endl; |
|
87 check(P.from() == v1); |
80 |
88 |
81 cout << "P.length() == " << P.length() << endl; |
89 // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni, |
82 check(P.length() == 5); |
90 // de legalabb valami: |
|
91 #ifdef DEBUG |
|
92 cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl; |
|
93 rc = false; |
|
94 try { |
|
95 B.pushFront(e3); |
|
96 } |
|
97 catch(const Exception &e) { |
|
98 cout << "E: " << e.what() << endl; |
|
99 rc = true; |
|
100 } |
|
101 check(rc); |
|
102 #endif |
83 |
103 |
84 cout << "P.from()==s ? " << (P.from()==s) << endl; |
104 cout << "Hozzaadunk a vegehez ket elet..." << endl; |
85 check(P.from() == s); |
105 B.pushBack(e7); |
86 cout << "P.to()==t ? " << (P.to()==t) << endl; |
106 B.pushBack(e8); |
87 check(P.to() == t); |
107 cout << "P.length() == " << P.length() << endl; |
|
108 check(P.length() == 2); |
|
109 |
|
110 cout << "Es commitolunk...\n"; |
|
111 B.commit(); |
|
112 } |
|
113 cout << "P.length() == " << P.length() << endl; |
|
114 check(P.length() == 4); |
|
115 cout << "P.to()==v3 ? " << (P.to()==v3) << endl; |
|
116 check(P.to() == v3); |
88 |
117 |
89 cout << "Vegpont bellitasa: " << endl; |
118 cout << "Vegigiteralunk az eleken." << endl; |
90 rc = P.setTo(v2); |
119 typedef DPath::NodeIt NodeIt; |
91 cout << "Hibasra: " << rc << endl; |
120 typedef DPath::EdgeIt EdgeIt; |
92 check(!rc); |
121 EdgeIt e; |
93 rc = P.setTo(t); |
122 int i=1; |
94 cout << "Helyesre: " << rc << endl; |
123 for(P.first(e); P.valid(e); P.next(e), ++i) { |
95 check(rc); |
124 cout << i << ". el: " << e << endl; |
|
125 } |
96 |
126 |
97 cout << "Elek iranyitasanak ellenorzese." << endl; |
|
98 cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl; |
|
99 check(G.tail(e1)==s); |
|
100 |
127 |
101 cout << "Vegigiteralunk az eleken." << endl; |
128 // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni, |
102 typedef LPath::NodeIt NodeIt; |
129 // de legalabb valami: |
103 typedef LPath::EdgeIt EdgeIt; |
130 rc = false; |
104 EdgeIt e = P.first<EdgeIt>(); |
131 try { |
105 int i=1; |
132 cout << "Setting an edgeiter to a nonexistant edge." << endl; |
106 for(; P.valid(e); P.next(e), ++i) { |
133 P.nth(e,134); |
107 cout << i << ". el: " << P.graphEdge(e) |
134 rc = !debug; |
108 << ", elore el? " << P.isForward(e) << endl; |
135 } |
109 if(i>=3 && i<5) |
136 catch(const Exception &e) { |
110 check(!P.isForward(e)); |
137 cout << "E: " << e.what() << endl; |
111 else |
138 rc = debug; |
112 check(P.isForward(e)); |
139 } |
|
140 check(rc); |
113 } |
141 } |
114 |
142 |
115 { |
|
116 cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl; |
|
117 LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3)); |
|
118 |
|
119 cout << "P2.length() == " << P2.length() << endl; |
|
120 check(P2.length() == 2); |
|
121 |
|
122 cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl; |
|
123 check(P2.from() == v1); |
|
124 cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; |
|
125 check(P2.to() == v3); |
|
126 } |
|
127 { |
|
128 cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl; |
|
129 LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5)); |
|
130 |
|
131 cout << "P2.length() == " << P2.length() << endl; |
|
132 check(P2.length() == 5); |
|
133 |
|
134 cout << "P2.from()==s ? " << (P2.from()==s) << endl; |
|
135 check(P2.from() == s); |
|
136 cout << "P2.to()==t ? " << (P2.to()==t) << endl; |
|
137 check(P2.to() == t); |
|
138 } |
|
139 |
|
140 { |
|
141 cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..." |
|
142 << endl; |
|
143 LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3)); |
|
144 |
|
145 cout << "P2.length() == " << P2.length() << endl; |
|
146 check(P2.length() == 2); |
|
147 |
|
148 cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl; |
|
149 check(P2.from() == v1); |
|
150 cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; |
|
151 check(P2.to() == v3); |
|
152 } |
|
153 { |
|
154 cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..." |
|
155 << endl; |
|
156 LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3)); |
|
157 |
|
158 cout << "P2.length() == " << P2.length() << endl; |
|
159 check(P2.length() == 0); |
|
160 |
|
161 cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl; |
|
162 check(P2.from() == v3); |
|
163 cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; |
|
164 check(P2.to() == v3); |
|
165 } |
|
166 { |
|
167 cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..." |
|
168 << endl; |
|
169 LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0)); |
|
170 |
|
171 cout << "P2.length() == " << P2.length() << endl; |
|
172 check(P2.length() == 5); |
|
173 |
|
174 cout << "P2.from()==t ? " << (P2.from()==t) << endl; |
|
175 check(P2.from() == t); |
|
176 cout << "P2.to()==s ? " << (P2.to()==s) << endl; |
|
177 check(P2.to() == s); |
|
178 } |
|
179 |
143 |
180 } |
144 } |
|
145 catch(const std::exception &e) { |
|
146 cout << "Uncaught exception: " << e.what() << endl; |
|
147 return 1; |
|
148 } |
|
149 catch(...) { |
|
150 cout << "Something horrible happened: an exception which isn't " |
|
151 << "std::exception" << endl; |
|
152 return 2; |
|
153 } |
181 |
154 |
182 { |
|
183 cout << "\n\n\nDirPath tesztelese...\n"; |
|
184 |
|
185 |
|
186 cout << "Ures path letrehozasa" << endl; |
|
187 typedef DirPath<ListGraph> DPath; |
|
188 DPath P(G); |
|
189 |
|
190 cout << "P.length() == " << P.length() << endl; |
|
191 check(P.length() == 0); |
|
192 |
|
193 cout << "P.from() valid? " << G.valid(P.from()) << endl; |
|
194 check(! G.valid(P.from())); |
|
195 |
|
196 { |
|
197 cout << "Builder objektum letrehozasa" << endl; |
|
198 DPath::Builder B(P); |
|
199 |
|
200 cout << "Hozzaadunk az elejehez ket elet..." << endl; |
|
201 check(B.pushFront(e6)); |
|
202 check(B.pushFront(e5)); |
|
203 cout << "P.length() == " << P.length() << endl; |
|
204 check(P.length() == 0); |
|
205 |
|
206 cout << "Commitolunk..." << endl; |
|
207 B.commit(); |
|
208 |
|
209 cout << "P.length() == " << P.length() << endl; |
|
210 check(P.length() == 2); |
|
211 cout << "P.from() valid? " << G.valid(P.from()) << endl; |
|
212 check(G.valid(P.from())); |
|
213 cout << "P.from()==v1 ? " << (P.from()==v1) << endl; |
|
214 check(P.from() == v1); |
|
215 |
|
216 cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl; |
|
217 check(!B.pushFront(e3)); |
|
218 |
|
219 cout << "Hozzaadunk a vegehez ket elet..." << endl; |
|
220 check(B.pushBack(e7)); |
|
221 check(B.pushBack(e8)); |
|
222 cout << "P.length() == " << P.length() << endl; |
|
223 check(P.length() == 4); |
|
224 |
|
225 cout << "Hozzaadunk az elejehez meg egy elet..." << endl; |
|
226 check(B.pushFront(e4)); |
|
227 cout << "P.length() == " << P.length() << endl; |
|
228 check(P.length() == 4); |
|
229 |
|
230 cout << "Es megvarjuk, amig megszunik a Builder...\n"; |
|
231 } |
|
232 cout << "P.length() == " << P.length() << endl; |
|
233 check(P.length() == 5); |
|
234 cout << "P.from()==v2 ? " << (P.from()==v2) << endl; |
|
235 check(P.from() == v2); |
|
236 |
|
237 cout << "Vegigiteralunk az eleken." << endl; |
|
238 typedef DPath::NodeIt NodeIt; |
|
239 typedef DPath::EdgeIt EdgeIt; |
|
240 EdgeIt e; |
|
241 int i=1; |
|
242 for(P.first(e); P.valid(e); P.next(e), ++i) { |
|
243 cout << i << ". el: " << e << endl; |
|
244 } |
|
245 } |
|
246 |
155 |
247 cout << (passed ? "All tests passed." : "Some of the tests failed!!!") |
156 cout << (passed ? "All tests passed." : "Some of the tests failed!!!") |
248 << endl; |
157 << endl; |
249 |
158 |
250 return passed ? 0 : 1; |
159 return passed ? 0 : 1; |