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