[209] | 1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
[25] | 2 | * |
---|
[209] | 3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
[25] | 4 | * |
---|
[761] | 5 | * Copyright (C) 2003-2011 |
---|
[25] | 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include <deque> |
---|
| 20 | #include <set> |
---|
| 21 | |
---|
| 22 | #include <lemon/concept_check.h> |
---|
| 23 | #include <lemon/concepts/maps.h> |
---|
| 24 | #include <lemon/maps.h> |
---|
[684] | 25 | #include <lemon/list_graph.h> |
---|
[25] | 26 | |
---|
| 27 | #include "test_tools.h" |
---|
| 28 | |
---|
| 29 | using namespace lemon; |
---|
| 30 | using namespace lemon::concepts; |
---|
| 31 | |
---|
| 32 | struct A {}; |
---|
| 33 | inline bool operator<(A, A) { return true; } |
---|
| 34 | struct B {}; |
---|
| 35 | |
---|
[94] | 36 | class C { |
---|
| 37 | int x; |
---|
| 38 | public: |
---|
| 39 | C(int _x) : x(_x) {} |
---|
| 40 | }; |
---|
| 41 | |
---|
[25] | 42 | class F { |
---|
| 43 | public: |
---|
| 44 | typedef A argument_type; |
---|
| 45 | typedef B result_type; |
---|
| 46 | |
---|
[80] | 47 | B operator()(const A&) const { return B(); } |
---|
| 48 | private: |
---|
| 49 | F& operator=(const F&); |
---|
[25] | 50 | }; |
---|
| 51 | |
---|
[80] | 52 | int func(A) { return 3; } |
---|
[25] | 53 | |
---|
[80] | 54 | int binc(int a, B) { return a+1; } |
---|
[25] | 55 | |
---|
[80] | 56 | typedef ReadMap<A, double> DoubleMap; |
---|
| 57 | typedef ReadWriteMap<A, double> DoubleWriteMap; |
---|
| 58 | typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap; |
---|
[25] | 59 | |
---|
[80] | 60 | typedef ReadMap<A, bool> BoolMap; |
---|
[25] | 61 | typedef ReadWriteMap<A, bool> BoolWriteMap; |
---|
[80] | 62 | typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap; |
---|
[25] | 63 | |
---|
| 64 | int main() |
---|
[80] | 65 | { |
---|
| 66 | // Map concepts |
---|
[25] | 67 | checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
---|
[94] | 68 | checkConcept<ReadMap<A,C>, ReadMap<A,C> >(); |
---|
[25] | 69 | checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
---|
[94] | 70 | checkConcept<WriteMap<A,C>, WriteMap<A,C> >(); |
---|
[25] | 71 | checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >(); |
---|
[94] | 72 | checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >(); |
---|
[761] | 73 | checkConcept<ReferenceMap<A,B,B&,const B&>, |
---|
| 74 | ReferenceMap<A,B,B&,const B&> >(); |
---|
| 75 | checkConcept<ReferenceMap<A,C,C&,const C&>, |
---|
| 76 | ReferenceMap<A,C,C&,const C&> >(); |
---|
[25] | 77 | |
---|
[80] | 78 | // NullMap |
---|
| 79 | { |
---|
| 80 | checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >(); |
---|
| 81 | NullMap<A,B> map1; |
---|
| 82 | NullMap<A,B> map2 = map1; |
---|
[792] | 83 | ignore_unused_variable_warning(map2); |
---|
[80] | 84 | map1 = nullMap<A,B>(); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | // ConstMap |
---|
| 88 | { |
---|
| 89 | checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >(); |
---|
[123] | 90 | checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >(); |
---|
[80] | 91 | ConstMap<A,B> map1; |
---|
[136] | 92 | ConstMap<A,B> map2 = B(); |
---|
[80] | 93 | ConstMap<A,B> map3 = map1; |
---|
[792] | 94 | ignore_unused_variable_warning(map2,map3); |
---|
| 95 | |
---|
[80] | 96 | map1 = constMap<A>(B()); |
---|
[123] | 97 | map1 = constMap<A,B>(); |
---|
[80] | 98 | map1.setAll(B()); |
---|
[123] | 99 | ConstMap<A,C> map4(C(1)); |
---|
| 100 | ConstMap<A,C> map5 = map4; |
---|
[792] | 101 | ignore_unused_variable_warning(map5); |
---|
| 102 | |
---|
[123] | 103 | map4 = constMap<A>(C(2)); |
---|
| 104 | map4.setAll(C(3)); |
---|
[82] | 105 | |
---|
[80] | 106 | checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >(); |
---|
| 107 | check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap"); |
---|
| 108 | |
---|
| 109 | checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >(); |
---|
[123] | 110 | ConstMap<A,Const<int,10> > map6; |
---|
| 111 | ConstMap<A,Const<int,10> > map7 = map6; |
---|
| 112 | map6 = constMap<A,int,10>(); |
---|
| 113 | map7 = constMap<A,Const<int,10> >(); |
---|
[210] | 114 | check(map6[A()] == 10 && map7[A()] == 10, |
---|
| 115 | "Something is wrong with ConstMap"); |
---|
[80] | 116 | } |
---|
| 117 | |
---|
| 118 | // IdentityMap |
---|
| 119 | { |
---|
| 120 | checkConcept<ReadMap<A,A>, IdentityMap<A> >(); |
---|
| 121 | IdentityMap<A> map1; |
---|
| 122 | IdentityMap<A> map2 = map1; |
---|
[792] | 123 | ignore_unused_variable_warning(map2); |
---|
| 124 | |
---|
[80] | 125 | map1 = identityMap<A>(); |
---|
[82] | 126 | |
---|
[80] | 127 | checkConcept<ReadMap<double,double>, IdentityMap<double> >(); |
---|
[210] | 128 | check(identityMap<double>()[1.0] == 1.0 && |
---|
| 129 | identityMap<double>()[3.14] == 3.14, |
---|
[80] | 130 | "Something is wrong with IdentityMap"); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | // RangeMap |
---|
| 134 | { |
---|
| 135 | checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >(); |
---|
| 136 | RangeMap<B> map1; |
---|
| 137 | RangeMap<B> map2(10); |
---|
| 138 | RangeMap<B> map3(10,B()); |
---|
| 139 | RangeMap<B> map4 = map1; |
---|
| 140 | RangeMap<B> map5 = rangeMap<B>(); |
---|
| 141 | RangeMap<B> map6 = rangeMap<B>(10); |
---|
| 142 | RangeMap<B> map7 = rangeMap(10,B()); |
---|
| 143 | |
---|
| 144 | checkConcept< ReferenceMap<int, double, double&, const double&>, |
---|
| 145 | RangeMap<double> >(); |
---|
| 146 | std::vector<double> v(10, 0); |
---|
| 147 | v[5] = 100; |
---|
| 148 | RangeMap<double> map8(v); |
---|
| 149 | RangeMap<double> map9 = rangeMap(v); |
---|
| 150 | check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100, |
---|
| 151 | "Something is wrong with RangeMap"); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | // SparseMap |
---|
| 155 | { |
---|
| 156 | checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >(); |
---|
| 157 | SparseMap<A,B> map1; |
---|
[136] | 158 | SparseMap<A,B> map2 = B(); |
---|
[80] | 159 | SparseMap<A,B> map3 = sparseMap<A,B>(); |
---|
| 160 | SparseMap<A,B> map4 = sparseMap<A>(B()); |
---|
| 161 | |
---|
| 162 | checkConcept< ReferenceMap<double, int, int&, const int&>, |
---|
| 163 | SparseMap<double, int> >(); |
---|
| 164 | std::map<double, int> m; |
---|
| 165 | SparseMap<double, int> map5(m); |
---|
| 166 | SparseMap<double, int> map6(m,10); |
---|
| 167 | SparseMap<double, int> map7 = sparseMap(m); |
---|
| 168 | SparseMap<double, int> map8 = sparseMap(m,10); |
---|
| 169 | |
---|
[210] | 170 | check(map5[1.0] == 0 && map5[3.14] == 0 && |
---|
| 171 | map6[1.0] == 10 && map6[3.14] == 10, |
---|
[80] | 172 | "Something is wrong with SparseMap"); |
---|
| 173 | map5[1.0] = map6[3.14] = 100; |
---|
[210] | 174 | check(map5[1.0] == 100 && map5[3.14] == 0 && |
---|
| 175 | map6[1.0] == 10 && map6[3.14] == 100, |
---|
[80] | 176 | "Something is wrong with SparseMap"); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | // ComposeMap |
---|
| 180 | { |
---|
| 181 | typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap; |
---|
| 182 | checkConcept<ReadMap<B,double>, CompMap>(); |
---|
[477] | 183 | CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>()); |
---|
[792] | 184 | ignore_unused_variable_warning(map1); |
---|
[80] | 185 | CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>()); |
---|
[792] | 186 | ignore_unused_variable_warning(map2); |
---|
[82] | 187 | |
---|
[80] | 188 | SparseMap<double, bool> m1(false); m1[3.14] = true; |
---|
| 189 | RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14; |
---|
[210] | 190 | check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], |
---|
| 191 | "Something is wrong with ComposeMap") |
---|
[80] | 192 | } |
---|
| 193 | |
---|
| 194 | // CombineMap |
---|
| 195 | { |
---|
| 196 | typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap; |
---|
| 197 | checkConcept<ReadMap<A,double>, CombMap>(); |
---|
[477] | 198 | CombMap map1 = CombMap(DoubleMap(), DoubleMap()); |
---|
[792] | 199 | ignore_unused_variable_warning(map1); |
---|
[80] | 200 | CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>()); |
---|
[792] | 201 | ignore_unused_variable_warning(map2); |
---|
[80] | 202 | |
---|
| 203 | check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3, |
---|
| 204 | "Something is wrong with CombineMap"); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | // FunctorToMap, MapToFunctor |
---|
| 208 | { |
---|
| 209 | checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >(); |
---|
| 210 | checkConcept<ReadMap<A,B>, FunctorToMap<F> >(); |
---|
| 211 | FunctorToMap<F> map1; |
---|
[477] | 212 | FunctorToMap<F> map2 = FunctorToMap<F>(F()); |
---|
[792] | 213 | ignore_unused_variable_warning(map2); |
---|
| 214 | |
---|
[80] | 215 | B b = functorToMap(F())[A()]; |
---|
[792] | 216 | ignore_unused_variable_warning(b); |
---|
[80] | 217 | |
---|
| 218 | checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); |
---|
[792] | 219 | MapToFunctor<ReadMap<A,B> > map = |
---|
| 220 | MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>()); |
---|
| 221 | ignore_unused_variable_warning(map); |
---|
[80] | 222 | |
---|
[210] | 223 | check(functorToMap(&func)[A()] == 3, |
---|
| 224 | "Something is wrong with FunctorToMap"); |
---|
| 225 | check(mapToFunctor(constMap<A,int>(2))(A()) == 2, |
---|
| 226 | "Something is wrong with MapToFunctor"); |
---|
| 227 | check(mapToFunctor(functorToMap(&func))(A()) == 3 && |
---|
| 228 | mapToFunctor(functorToMap(&func))[A()] == 3, |
---|
[80] | 229 | "Something is wrong with FunctorToMap or MapToFunctor"); |
---|
| 230 | check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2, |
---|
| 231 | "Something is wrong with FunctorToMap or MapToFunctor"); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | // ConvertMap |
---|
| 235 | { |
---|
[210] | 236 | checkConcept<ReadMap<double,double>, |
---|
| 237 | ConvertMap<ReadMap<double, int>, double> >(); |
---|
[80] | 238 | ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true)); |
---|
[792] | 239 | ignore_unused_variable_warning(map1); |
---|
[80] | 240 | ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false)); |
---|
[792] | 241 | ignore_unused_variable_warning(map2); |
---|
| 242 | |
---|
[80] | 243 | } |
---|
| 244 | |
---|
| 245 | // ForkMap |
---|
| 246 | { |
---|
| 247 | checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >(); |
---|
[82] | 248 | |
---|
[80] | 249 | typedef RangeMap<double> RM; |
---|
| 250 | typedef SparseMap<int, double> SM; |
---|
| 251 | RM m1(10, -1); |
---|
| 252 | SM m2(-1); |
---|
| 253 | checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >(); |
---|
| 254 | checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >(); |
---|
| 255 | ForkMap<RM, SM> map1(m1,m2); |
---|
| 256 | ForkMap<SM, RM> map2 = forkMap(m2,m1); |
---|
| 257 | map2.set(5, 10); |
---|
[210] | 258 | check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && |
---|
| 259 | m2[5] == 10 && map2[1] == -1 && map2[5] == 10, |
---|
[80] | 260 | "Something is wrong with ForkMap"); |
---|
| 261 | } |
---|
[82] | 262 | |
---|
[80] | 263 | // Arithmetic maps: |
---|
| 264 | // - AddMap, SubMap, MulMap, DivMap |
---|
| 265 | // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap |
---|
| 266 | // - NegMap, NegWriteMap, AbsMap |
---|
| 267 | { |
---|
| 268 | checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >(); |
---|
| 269 | checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >(); |
---|
| 270 | checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >(); |
---|
| 271 | checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >(); |
---|
[82] | 272 | |
---|
[80] | 273 | ConstMap<int, double> c1(1.0), c2(3.14); |
---|
| 274 | IdentityMap<int> im; |
---|
| 275 | ConvertMap<IdentityMap<int>, double> id(im); |
---|
[210] | 276 | check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0, |
---|
| 277 | "Something is wrong with AddMap"); |
---|
| 278 | check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0, |
---|
| 279 | "Something is wrong with SubMap"); |
---|
| 280 | check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28, |
---|
| 281 | "Something is wrong with MulMap"); |
---|
| 282 | check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57, |
---|
| 283 | "Something is wrong with DivMap"); |
---|
[82] | 284 | |
---|
[80] | 285 | checkConcept<DoubleMap, ShiftMap<DoubleMap> >(); |
---|
| 286 | checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >(); |
---|
| 287 | checkConcept<DoubleMap, ScaleMap<DoubleMap> >(); |
---|
| 288 | checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >(); |
---|
| 289 | checkConcept<DoubleMap, NegMap<DoubleMap> >(); |
---|
| 290 | checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >(); |
---|
| 291 | checkConcept<DoubleMap, AbsMap<DoubleMap> >(); |
---|
[25] | 292 | |
---|
[80] | 293 | check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0, |
---|
| 294 | "Something is wrong with ShiftMap"); |
---|
[210] | 295 | check(shiftWriteMap(id, 2.0)[1] == 3.0 && |
---|
| 296 | shiftWriteMap(id, 2.0)[10] == 12.0, |
---|
[80] | 297 | "Something is wrong with ShiftWriteMap"); |
---|
| 298 | check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0, |
---|
| 299 | "Something is wrong with ScaleMap"); |
---|
[210] | 300 | check(scaleWriteMap(id, 2.0)[1] == 2.0 && |
---|
| 301 | scaleWriteMap(id, 2.0)[10] == 20.0, |
---|
[80] | 302 | "Something is wrong with ScaleWriteMap"); |
---|
| 303 | check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0, |
---|
| 304 | "Something is wrong with NegMap"); |
---|
| 305 | check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0, |
---|
| 306 | "Something is wrong with NegWriteMap"); |
---|
| 307 | check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0, |
---|
| 308 | "Something is wrong with AbsMap"); |
---|
| 309 | } |
---|
[82] | 310 | |
---|
| 311 | // Logical maps: |
---|
| 312 | // - TrueMap, FalseMap |
---|
| 313 | // - AndMap, OrMap |
---|
| 314 | // - NotMap, NotWriteMap |
---|
| 315 | // - EqualMap, LessMap |
---|
[80] | 316 | { |
---|
[82] | 317 | checkConcept<BoolMap, TrueMap<A> >(); |
---|
| 318 | checkConcept<BoolMap, FalseMap<A> >(); |
---|
| 319 | checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >(); |
---|
| 320 | checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >(); |
---|
[80] | 321 | checkConcept<BoolMap, NotMap<BoolMap> >(); |
---|
| 322 | checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >(); |
---|
[82] | 323 | checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >(); |
---|
| 324 | checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >(); |
---|
| 325 | |
---|
| 326 | TrueMap<int> tm; |
---|
| 327 | FalseMap<int> fm; |
---|
[80] | 328 | RangeMap<bool> rm(2); |
---|
| 329 | rm[0] = true; rm[1] = false; |
---|
[210] | 330 | check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && |
---|
| 331 | !andMap(fm,rm)[0] && !andMap(fm,rm)[1], |
---|
[82] | 332 | "Something is wrong with AndMap"); |
---|
[210] | 333 | check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && |
---|
| 334 | orMap(fm,rm)[0] && !orMap(fm,rm)[1], |
---|
[82] | 335 | "Something is wrong with OrMap"); |
---|
[210] | 336 | check(!notMap(rm)[0] && notMap(rm)[1], |
---|
| 337 | "Something is wrong with NotMap"); |
---|
| 338 | check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], |
---|
| 339 | "Something is wrong with NotWriteMap"); |
---|
[82] | 340 | |
---|
| 341 | ConstMap<int, double> cm(2.0); |
---|
| 342 | IdentityMap<int> im; |
---|
| 343 | ConvertMap<IdentityMap<int>, double> id(im); |
---|
| 344 | check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3], |
---|
| 345 | "Something is wrong with LessMap"); |
---|
| 346 | check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3], |
---|
| 347 | "Something is wrong with EqualMap"); |
---|
[80] | 348 | } |
---|
[209] | 349 | |
---|
[167] | 350 | // LoggerBoolMap |
---|
[159] | 351 | { |
---|
| 352 | typedef std::vector<int> vec; |
---|
| 353 | vec v1; |
---|
| 354 | vec v2(10); |
---|
[210] | 355 | LoggerBoolMap<std::back_insert_iterator<vec> > |
---|
| 356 | map1(std::back_inserter(v1)); |
---|
[167] | 357 | LoggerBoolMap<vec::iterator> map2(v2.begin()); |
---|
[159] | 358 | map1.set(10, false); |
---|
| 359 | map1.set(20, true); map2.set(20, true); |
---|
| 360 | map1.set(30, false); map2.set(40, false); |
---|
| 361 | map1.set(50, true); map2.set(50, true); |
---|
| 362 | map1.set(60, true); map2.set(60, true); |
---|
| 363 | check(v1.size() == 3 && v2.size() == 10 && |
---|
[210] | 364 | v1[0]==20 && v1[1]==50 && v1[2]==60 && |
---|
| 365 | v2[0]==20 && v2[1]==50 && v2[2]==60, |
---|
[167] | 366 | "Something is wrong with LoggerBoolMap"); |
---|
[209] | 367 | |
---|
[159] | 368 | int i = 0; |
---|
[167] | 369 | for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin(); |
---|
[159] | 370 | it != map2.end(); ++it ) |
---|
[167] | 371 | check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); |
---|
[159] | 372 | } |
---|
[761] | 373 | |
---|
[684] | 374 | // CrossRefMap |
---|
| 375 | { |
---|
| 376 | typedef ListDigraph Graph; |
---|
| 377 | DIGRAPH_TYPEDEFS(Graph); |
---|
| 378 | |
---|
| 379 | checkConcept<ReadWriteMap<Node, int>, |
---|
| 380 | CrossRefMap<Graph, Node, int> >(); |
---|
[761] | 381 | |
---|
[684] | 382 | Graph gr; |
---|
| 383 | typedef CrossRefMap<Graph, Node, char> CRMap; |
---|
| 384 | typedef CRMap::ValueIterator ValueIt; |
---|
| 385 | CRMap map(gr); |
---|
[761] | 386 | |
---|
[684] | 387 | Node n0 = gr.addNode(); |
---|
| 388 | Node n1 = gr.addNode(); |
---|
| 389 | Node n2 = gr.addNode(); |
---|
[761] | 390 | |
---|
[684] | 391 | map.set(n0, 'A'); |
---|
| 392 | map.set(n1, 'B'); |
---|
| 393 | map.set(n2, 'C'); |
---|
| 394 | map.set(n2, 'A'); |
---|
| 395 | map.set(n0, 'C'); |
---|
| 396 | |
---|
| 397 | check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A', |
---|
| 398 | "Wrong CrossRefMap"); |
---|
| 399 | check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap"); |
---|
| 400 | check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap"); |
---|
| 401 | check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap"); |
---|
| 402 | |
---|
| 403 | ValueIt it = map.beginValue(); |
---|
| 404 | check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && |
---|
| 405 | it == map.endValue(), "Wrong value iterator"); |
---|
| 406 | } |
---|
[25] | 407 | |
---|
| 408 | return 0; |
---|
| 409 | } |
---|