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