hegyi@815
|
1 |
#include <string>
|
hegyi@815
|
2 |
#include <iostream>
|
hegyi@815
|
3 |
//#include <path.h>
|
hegyi@815
|
4 |
#include <path_skeleton.h>
|
hegyi@815
|
5 |
#include <list_graph.h>
|
hegyi@815
|
6 |
|
hegyi@815
|
7 |
using namespace std;
|
alpar@921
|
8 |
using namespace lemon;
|
hegyi@815
|
9 |
using namespace skeleton;
|
hegyi@815
|
10 |
|
hegyi@815
|
11 |
bool passed = true;
|
hegyi@815
|
12 |
|
hegyi@815
|
13 |
void check(bool rc) {
|
hegyi@815
|
14 |
passed = passed && rc;
|
hegyi@815
|
15 |
if(!rc) {
|
hegyi@815
|
16 |
cout << "Test failed!" << endl;
|
hegyi@815
|
17 |
}
|
hegyi@815
|
18 |
}
|
hegyi@815
|
19 |
|
hegyi@815
|
20 |
#ifdef DEBUG
|
hegyi@815
|
21 |
const bool debug = true;
|
hegyi@815
|
22 |
#else
|
hegyi@815
|
23 |
const bool debug = false;
|
hegyi@815
|
24 |
#endif
|
hegyi@815
|
25 |
|
hegyi@815
|
26 |
|
hegyi@815
|
27 |
int main() {
|
hegyi@815
|
28 |
|
hegyi@815
|
29 |
try {
|
hegyi@815
|
30 |
|
hegyi@815
|
31 |
typedef ListGraph::Node Node;
|
hegyi@815
|
32 |
typedef ListGraph::Edge Edge;
|
hegyi@815
|
33 |
|
hegyi@815
|
34 |
ListGraph G;
|
hegyi@815
|
35 |
|
hegyi@815
|
36 |
Node s=G.addNode();
|
hegyi@815
|
37 |
Node v1=G.addNode();
|
hegyi@815
|
38 |
Node v2=G.addNode();
|
hegyi@815
|
39 |
Node v3=G.addNode();
|
hegyi@815
|
40 |
Node v4=G.addNode();
|
hegyi@815
|
41 |
Node t=G.addNode();
|
hegyi@815
|
42 |
|
hegyi@815
|
43 |
Edge e1 = G.addEdge(s, v1);
|
hegyi@815
|
44 |
Edge e2 = G.addEdge(s, v2);
|
hegyi@815
|
45 |
Edge e3 = G.addEdge(v1, v2);
|
hegyi@815
|
46 |
Edge e4 = G.addEdge(v2, v1);
|
hegyi@815
|
47 |
Edge e5 = G.addEdge(v1, v3);
|
hegyi@815
|
48 |
Edge e6 = G.addEdge(v3, v2);
|
hegyi@815
|
49 |
Edge e7 = G.addEdge(v2, v4);
|
hegyi@815
|
50 |
Edge e8 = G.addEdge(v4, v3);
|
hegyi@815
|
51 |
Edge e9 = G.addEdge(v3, t);
|
hegyi@815
|
52 |
Edge e10 = G.addEdge(v4, t);
|
hegyi@815
|
53 |
|
hegyi@815
|
54 |
bool rc;
|
hegyi@815
|
55 |
|
hegyi@815
|
56 |
{
|
hegyi@815
|
57 |
cout << "\n\n\nDirPath tesztelese...\n";
|
hegyi@815
|
58 |
|
hegyi@815
|
59 |
|
hegyi@815
|
60 |
cout << "Ures path letrehozasa" << endl;
|
hegyi@815
|
61 |
//typedef DirPath<ListGraph> DPath;
|
hegyi@815
|
62 |
typedef Path <ListGraph> DPath;
|
hegyi@815
|
63 |
DPath P(G);
|
hegyi@815
|
64 |
|
hegyi@815
|
65 |
cout << "P.length() == " << P.length() << endl;
|
hegyi@815
|
66 |
check(P.length() == 0);
|
hegyi@815
|
67 |
|
hegyi@815
|
68 |
#ifdef SKELETON
|
hegyi@815
|
69 |
cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
|
hegyi@815
|
70 |
check(! (P.tail()!=INVALID));
|
hegyi@815
|
71 |
#else
|
hegyi@815
|
72 |
cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
|
hegyi@815
|
73 |
check(! (P.to()!=INVALID));
|
hegyi@815
|
74 |
#endif
|
hegyi@815
|
75 |
{
|
hegyi@815
|
76 |
cout << "Builder objektum letrehozasa" << endl;
|
hegyi@815
|
77 |
DPath::Builder B(P);
|
hegyi@815
|
78 |
|
hegyi@815
|
79 |
cout << "Hozzaadunk az elejehez ket elet..." << endl;
|
hegyi@815
|
80 |
B.pushFront(e6);
|
hegyi@815
|
81 |
B.pushFront(e5);
|
hegyi@815
|
82 |
cout << "P.length() == " << P.length() << endl;
|
hegyi@815
|
83 |
check(P.length() == 0);
|
hegyi@815
|
84 |
|
hegyi@815
|
85 |
cout << "Commitolunk..." << endl;
|
hegyi@815
|
86 |
B.commit();
|
hegyi@815
|
87 |
|
hegyi@815
|
88 |
cout << "P.length() == " << P.length() << endl;
|
hegyi@815
|
89 |
check(P.length() == 2);
|
hegyi@815
|
90 |
|
hegyi@815
|
91 |
#ifdef SKELETON
|
hegyi@815
|
92 |
cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl;
|
hegyi@815
|
93 |
check(P.tail()!=INVALID);
|
hegyi@815
|
94 |
cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl;
|
hegyi@815
|
95 |
check(P.tail() == v1);
|
hegyi@815
|
96 |
#else
|
hegyi@815
|
97 |
cout << "P.tail() valid? " << (P.from()!=INVALID) << endl;
|
hegyi@815
|
98 |
check(P.from()!=INVALID);
|
hegyi@815
|
99 |
cout << "P.tail()==v1 ? " << (P.from()==v1) << endl;
|
hegyi@815
|
100 |
check(P.from() == v1);
|
hegyi@815
|
101 |
#endif
|
hegyi@815
|
102 |
|
hegyi@815
|
103 |
// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
|
hegyi@815
|
104 |
// de legalabb valami:
|
hegyi@815
|
105 |
#ifdef DEBUG
|
hegyi@815
|
106 |
cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
|
hegyi@815
|
107 |
rc = false;
|
hegyi@815
|
108 |
try {
|
hegyi@815
|
109 |
B.pushFront(e3);
|
hegyi@815
|
110 |
}
|
hegyi@815
|
111 |
catch(const Exception &e) {
|
hegyi@815
|
112 |
cout << "E: " << e.what() << endl;
|
hegyi@815
|
113 |
rc = true;
|
hegyi@815
|
114 |
}
|
hegyi@815
|
115 |
check(rc);
|
hegyi@815
|
116 |
#endif
|
hegyi@815
|
117 |
|
hegyi@815
|
118 |
cout << "Hozzaadunk a vegehez ket elet..." << endl;
|
hegyi@815
|
119 |
B.pushBack(e7);
|
hegyi@815
|
120 |
B.pushBack(e8);
|
hegyi@815
|
121 |
cout << "P.length() == " << P.length() << endl;
|
hegyi@815
|
122 |
check(P.length() == 2);
|
hegyi@815
|
123 |
|
hegyi@815
|
124 |
cout << "Es commitolunk...\n";
|
hegyi@815
|
125 |
B.commit();
|
hegyi@815
|
126 |
}
|
hegyi@815
|
127 |
cout << "P.length() == " << P.length() << endl;
|
hegyi@815
|
128 |
check(P.length() == 4);
|
hegyi@815
|
129 |
|
hegyi@815
|
130 |
#ifdef SKELETON
|
hegyi@815
|
131 |
cout << "P.head()==v3 ? " << (P.head()==v3) << endl;
|
hegyi@815
|
132 |
check(P.head() == v3);
|
hegyi@815
|
133 |
#else
|
hegyi@815
|
134 |
cout << "P.head()==v3 ? " << (P.to()==v3) << endl;
|
hegyi@815
|
135 |
check(P.to() == v3);
|
hegyi@815
|
136 |
#endif
|
hegyi@815
|
137 |
|
hegyi@815
|
138 |
cout << "Vegigiteralunk az eleken." << endl;
|
hegyi@815
|
139 |
typedef DPath::NodeIt NodeIt;
|
hegyi@815
|
140 |
typedef DPath::EdgeIt EdgeIt;
|
hegyi@815
|
141 |
EdgeIt e;
|
hegyi@815
|
142 |
int i=1;
|
hegyi@815
|
143 |
for(P.first(e); e!=INVALID; ++e, ++i) {
|
hegyi@815
|
144 |
cout << i << ". el: " <</* e << */endl;
|
hegyi@815
|
145 |
}
|
hegyi@815
|
146 |
|
hegyi@815
|
147 |
|
hegyi@815
|
148 |
// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
|
hegyi@815
|
149 |
// de legalabb valami:
|
hegyi@815
|
150 |
|
hegyi@815
|
151 |
#ifdef DEBUG
|
hegyi@815
|
152 |
rc = false;
|
hegyi@815
|
153 |
try {
|
hegyi@815
|
154 |
cout << "Setting an edgeiter to a nonexistant edge." << endl;
|
hegyi@815
|
155 |
//P.nth(e,134);
|
hegyi@815
|
156 |
rc = !debug;
|
hegyi@815
|
157 |
}
|
hegyi@815
|
158 |
catch(const Exception &e) {
|
hegyi@815
|
159 |
cout << "E: " << e.what() << endl;
|
hegyi@815
|
160 |
rc = debug;
|
hegyi@815
|
161 |
}
|
hegyi@815
|
162 |
check(rc);
|
hegyi@815
|
163 |
#endif
|
hegyi@815
|
164 |
}
|
hegyi@815
|
165 |
|
hegyi@815
|
166 |
}
|
hegyi@815
|
167 |
catch(const std::exception &e) {
|
hegyi@815
|
168 |
cout << "Uncaught exception: " << e.what() << endl;
|
hegyi@815
|
169 |
return 1;
|
hegyi@815
|
170 |
}
|
hegyi@815
|
171 |
catch(...) {
|
hegyi@815
|
172 |
cout << "Something horrible happened: an exception which isn't "
|
hegyi@815
|
173 |
<< "std::exception" << endl;
|
hegyi@815
|
174 |
return 2;
|
hegyi@815
|
175 |
}
|
hegyi@815
|
176 |
|
hegyi@815
|
177 |
|
hegyi@815
|
178 |
cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
|
hegyi@815
|
179 |
<< endl;
|
hegyi@815
|
180 |
|
hegyi@815
|
181 |
return passed ? 0 : 1;
|
hegyi@815
|
182 |
}
|