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 | cout << "Ures path letrehozasa" << endl; |
---|
47 | typedef Path<ListGraph> LPath; |
---|
48 | LPath P(G); |
---|
49 | |
---|
50 | cout << "P.length() == " << P.length() << endl; |
---|
51 | check(P.length() == 0); |
---|
52 | |
---|
53 | cout << "P.from() valid? " << G.valid(P.from()) << endl; |
---|
54 | check(! G.valid(P.from())); |
---|
55 | |
---|
56 | cout << "Hozzaadunk ket elet..." << endl; |
---|
57 | check(P.pushBack(e1)); |
---|
58 | check(P.pushBack(e3)); |
---|
59 | cout << "P.length() == " << P.length() << endl; |
---|
60 | check(P.length() == 2); |
---|
61 | |
---|
62 | cout << "P.from() valid? " << G.valid(P.from()) << endl; |
---|
63 | check(G.valid(P.from())); |
---|
64 | |
---|
65 | cout << "P.from()==s ? " << (P.from()==s) << endl; |
---|
66 | check(P.from() == s); |
---|
67 | |
---|
68 | cout << "Hozzaadunk egy nem illeszkedo elt." << endl; |
---|
69 | rc = P.pushBack(e8); |
---|
70 | cout << "Sukerult: " << rc << endl; |
---|
71 | check(!rc); |
---|
72 | |
---|
73 | cout << "Meg 3 el hozzaadasa, nem mind sorrendben..." << endl; |
---|
74 | check(P.pushBack(e6)); |
---|
75 | check(P.pushBack(e8)); |
---|
76 | check(P.pushBack(e10)); |
---|
77 | |
---|
78 | cout << "P.length() == " << P.length() << endl; |
---|
79 | check(P.length() == 5); |
---|
80 | |
---|
81 | cout << "P.from()==s ? " << (P.from()==s) << endl; |
---|
82 | check(P.from() == s); |
---|
83 | cout << "P.to()==t ? " << (P.to()==t) << endl; |
---|
84 | check(P.to() == t); |
---|
85 | |
---|
86 | cout << "Vegpont bellitasa: " << endl; |
---|
87 | rc = P.setTo(v2); |
---|
88 | cout << "Hibasra: " << rc << endl; |
---|
89 | check(!rc); |
---|
90 | rc = P.setTo(t); |
---|
91 | cout << "Helyesre: " << rc << endl; |
---|
92 | check(rc); |
---|
93 | |
---|
94 | cout << "Elek iranyitasanak ellenorzese." << endl; |
---|
95 | cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl; |
---|
96 | check(G.tail(e1)==s); |
---|
97 | |
---|
98 | cout << "Vegigiteralunk az eleken." << endl; |
---|
99 | typedef LPath::NodeIt NodeIt; |
---|
100 | typedef LPath::EdgeIt EdgeIt; |
---|
101 | EdgeIt e = P.first<EdgeIt>(); |
---|
102 | int i=1; |
---|
103 | for(; P.valid(e); P.next(e), ++i) { |
---|
104 | cout << i << ". el: " << P.graphEdge(e) |
---|
105 | << ", elore el? " << P.isForward(e) << endl; |
---|
106 | if(i>=3 && i<5) |
---|
107 | check(!P.isForward(e)); |
---|
108 | else |
---|
109 | check(P.isForward(e)); |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | cout << (passed ? "All tests passed." : "Some of the tests failed!!!") |
---|
115 | << endl; |
---|
116 | |
---|
117 | return passed ? 0 : 1; |
---|
118 | } |
---|