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 | cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl; |
---|
114 | LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3)); |
---|
115 | |
---|
116 | cout << "P2.length() == " << P2.length() << endl; |
---|
117 | check(P2.length() == 2); |
---|
118 | |
---|
119 | cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl; |
---|
120 | check(P2.from() == v1); |
---|
121 | cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; |
---|
122 | check(P2.to() == v3); |
---|
123 | } |
---|
124 | { |
---|
125 | cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl; |
---|
126 | LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5)); |
---|
127 | |
---|
128 | cout << "P2.length() == " << P2.length() << endl; |
---|
129 | check(P2.length() == 5); |
---|
130 | |
---|
131 | cout << "P2.from()==s ? " << (P2.from()==s) << endl; |
---|
132 | check(P2.from() == s); |
---|
133 | cout << "P2.to()==t ? " << (P2.to()==t) << endl; |
---|
134 | check(P2.to() == t); |
---|
135 | } |
---|
136 | |
---|
137 | { |
---|
138 | cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..." |
---|
139 | << endl; |
---|
140 | LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3)); |
---|
141 | |
---|
142 | cout << "P2.length() == " << P2.length() << endl; |
---|
143 | check(P2.length() == 2); |
---|
144 | |
---|
145 | cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl; |
---|
146 | check(P2.from() == v1); |
---|
147 | cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; |
---|
148 | check(P2.to() == v3); |
---|
149 | } |
---|
150 | { |
---|
151 | cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..." |
---|
152 | << endl; |
---|
153 | LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3)); |
---|
154 | |
---|
155 | cout << "P2.length() == " << P2.length() << endl; |
---|
156 | check(P2.length() == 0); |
---|
157 | |
---|
158 | cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl; |
---|
159 | check(P2.from() == v3); |
---|
160 | cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl; |
---|
161 | check(P2.to() == v3); |
---|
162 | } |
---|
163 | { |
---|
164 | cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..." |
---|
165 | << endl; |
---|
166 | LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0)); |
---|
167 | |
---|
168 | cout << "P2.length() == " << P2.length() << endl; |
---|
169 | check(P2.length() == 5); |
---|
170 | |
---|
171 | cout << "P2.from()==t ? " << (P2.from()==t) << endl; |
---|
172 | check(P2.from() == t); |
---|
173 | cout << "P2.to()==s ? " << (P2.to()==s) << endl; |
---|
174 | check(P2.to() == s); |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | cout << (passed ? "All tests passed." : "Some of the tests failed!!!") |
---|
179 | << endl; |
---|
180 | |
---|
181 | return passed ? 0 : 1; |
---|
182 | } |
---|