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