| 1 | #include <string> |
|---|
| 2 | #include <iostream> |
|---|
| 3 | |
|---|
| 4 | #include <path.h> |
|---|
| 5 | #include <list_graph.h> |
|---|
| 6 | |
|---|
| 7 | using namespace std; |
|---|
| 8 | using namespace hugo; |
|---|
| 9 | |
|---|
| 10 | bool passed = true; |
|---|
| 11 | |
|---|
| 12 | void check(bool rc) { |
|---|
| 13 | passed = passed && rc; |
|---|
| 14 | if(!rc) { |
|---|
| 15 | cout << "Test failed!" << endl; |
|---|
| 16 | } |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | int main() { |
|---|
| 20 | |
|---|
| 21 | typedef ListGraph::Node Node; |
|---|
| 22 | typedef ListGraph::Edge Edge; |
|---|
| 23 | |
|---|
| 24 | ListGraph G; |
|---|
| 25 | |
|---|
| 26 | Node s=G.addNode(); |
|---|
| 27 | Node v1=G.addNode(); |
|---|
| 28 | Node v2=G.addNode(); |
|---|
| 29 | Node v3=G.addNode(); |
|---|
| 30 | Node v4=G.addNode(); |
|---|
| 31 | Node t=G.addNode(); |
|---|
| 32 | |
|---|
| 33 | Edge e1 = G.addEdge(s, v1); |
|---|
| 34 | Edge e2 = G.addEdge(s, v2); |
|---|
| 35 | Edge e3 = G.addEdge(v1, v2); |
|---|
| 36 | Edge e4 = G.addEdge(v2, v1); |
|---|
| 37 | Edge e5 = G.addEdge(v1, v3); |
|---|
| 38 | Edge e6 = G.addEdge(v3, v2); |
|---|
| 39 | Edge e7 = G.addEdge(v2, v4); |
|---|
| 40 | Edge e8 = G.addEdge(v4, v3); |
|---|
| 41 | Edge e9 = G.addEdge(v3, t); |
|---|
| 42 | Edge e10 = G.addEdge(v4, t); |
|---|
| 43 | |
|---|
| 44 | bool rc; |
|---|
| 45 | |
|---|
| 46 | { |
|---|
| 47 | cout << "DynamicPath tesztelese...\n"; |
|---|
| 48 | |
|---|
| 49 | cout << "Ures path letrehozasa" << endl; |
|---|
| 50 | typedef DynamicPath<ListGraph> LPath; |
|---|
| 51 | LPath P(G); |
|---|
| 52 | |
|---|
| 53 | cout << "P.length() == " << P.length() << endl; |
|---|
| 54 | check(P.length() == 0); |
|---|
| 55 | |
|---|
| 56 | cout << "P.from() valid? " << G.valid(P.from()) << endl; |
|---|
| 57 | check(! G.valid(P.from())); |
|---|
| 58 | |
|---|
| 59 | cout << "Hozzaadunk ket elet..." << endl; |
|---|
| 60 | check(P.pushBack(e1)); |
|---|
| 61 | check(P.pushBack(e3)); |
|---|
| 62 | cout << "P.length() == " << P.length() << endl; |
|---|
| 63 | check(P.length() == 2); |
|---|
| 64 | |
|---|
| 65 | cout << "P.from() valid? " << G.valid(P.from()) << endl; |
|---|
| 66 | check(G.valid(P.from())); |
|---|
| 67 | |
|---|
| 68 | cout << "P.from()==s ? " << (P.from()==s) << endl; |
|---|
| 69 | check(P.from() == s); |
|---|
| 70 | |
|---|
| 71 | cout << "Hozzaadunk egy nem illeszkedo elt." << endl; |
|---|
| 72 | rc = P.pushBack(e8); |
|---|
| 73 | cout << "Sukerult: " << rc << endl; |
|---|
| 74 | check(!rc); |
|---|
| 75 | |
|---|
| 76 | cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl; |
|---|
| 77 | check(P.pushBack(e6)); |
|---|
| 78 | check(P.pushBack(e8)); |
|---|
| 79 | check(P.pushBack(e10)); |
|---|
| 80 | |
|---|
| 81 | cout << "P.length() == " << P.length() << endl; |
|---|
| 82 | check(P.length() == 5); |
|---|
| 83 | |
|---|
| 84 | cout << "P.from()==s ? " << (P.from()==s) << endl; |
|---|
| 85 | check(P.from() == s); |
|---|
| 86 | cout << "P.to()==t ? " << (P.to()==t) << endl; |
|---|
| 87 | check(P.to() == t); |
|---|
| 88 | |
|---|
| 89 | cout << "Vegpont bellitasa: " << endl; |
|---|
| 90 | rc = P.setTo(v2); |
|---|
| 91 | cout << "Hibasra: " << rc << endl; |
|---|
| 92 | check(!rc); |
|---|
| 93 | rc = P.setTo(t); |
|---|
| 94 | cout << "Helyesre: " << rc << endl; |
|---|
| 95 | check(rc); |
|---|
| 96 | |
|---|
| 97 | cout << "Elek iranyitasanak ellenorzese." << endl; |
|---|
| 98 | cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl; |
|---|
| 99 | check(G.tail(e1)==s); |
|---|
| 100 | |
|---|
| 101 | cout << "Vegigiteralunk az eleken." << endl; |
|---|
| 102 | typedef LPath::NodeIt NodeIt; |
|---|
| 103 | typedef LPath::EdgeIt EdgeIt; |
|---|
| 104 | EdgeIt e = P.first<EdgeIt>(); |
|---|
| 105 | int i=1; |
|---|
| 106 | for(; P.valid(e); P.next(e), ++i) { |
|---|
| 107 | cout << i << ". el: " << P.graphEdge(e) |
|---|
| 108 | << ", elore el? " << P.isForward(e) << endl; |
|---|
| 109 | if(i>=3 && i<5) |
|---|
| 110 | check(!P.isForward(e)); |
|---|
| 111 | else |
|---|
| 112 | check(P.isForward(e)); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 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 | |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 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 | |
|---|
| 247 | cout << (passed ? "All tests passed." : "Some of the tests failed!!!") |
|---|
| 248 | << endl; |
|---|
| 249 | |
|---|
| 250 | return passed ? 0 : 1; |
|---|
| 251 | } |
|---|