diff --git a/test/maps_test.cc b/test/maps_test.cc --- a/test/maps_test.cc +++ b/test/maps_test.cc @@ -2,7 +2,7 @@ * * This file is a part of LEMON, a generic C++ optimization library. * - * Copyright (C) 2003-2009 + * Copyright (C) 2003-2010 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * @@ -225,7 +225,8 @@ B b = functorToMap(F())[A()]; checkConcept, MapToFunctor > >(); - MapToFunctor > map = MapToFunctor >(ReadMap()); + MapToFunctor > map = + MapToFunctor >(ReadMap()); check(functorToMap(&func)[A()] == 3, "Something is wrong with FunctorToMap"); @@ -377,7 +378,7 @@ for ( LoggerBoolMap::Iterator it = map2.begin(); it != map2.end(); ++it ) check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); - + typedef ListDigraph Graph; DIGRAPH_TYPEDEFS(Graph); Graph gr; @@ -386,13 +387,13 @@ Node n1 = gr.addNode(); Node n2 = gr.addNode(); Node n3 = gr.addNode(); - + gr.addArc(n3, n0); gr.addArc(n3, n2); gr.addArc(n0, n2); gr.addArc(n2, n1); gr.addArc(n0, n1); - + { std::vector v; dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run(); @@ -403,12 +404,12 @@ { std::vector v(countNodes(gr)); dfs(gr).processedMap(loggerBoolMap(v.begin())).run(); - + check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3, "Something is wrong with LoggerBoolMap"); } } - + // IdMap, RangeIdMap { typedef ListDigraph Graph; @@ -418,22 +419,22 @@ checkConcept, IdMap >(); checkConcept, RangeIdMap >(); checkConcept, RangeIdMap >(); - + Graph gr; IdMap nmap(gr); IdMap amap(gr); RangeIdMap nrmap(gr); RangeIdMap armap(gr); - + Node n0 = gr.addNode(); Node n1 = gr.addNode(); Node n2 = gr.addNode(); - + Arc a0 = gr.addArc(n0, n1); Arc a1 = gr.addArc(n0, n2); Arc a2 = gr.addArc(n2, n1); Arc a3 = gr.addArc(n2, n0); - + check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap"); check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap"); check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap"); @@ -445,14 +446,14 @@ check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap"); check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap"); - + check(nrmap.size() == 3 && armap.size() == 4, "Wrong RangeIdMap::size()"); check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap"); check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap"); check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap"); - + check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap"); check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap"); @@ -460,32 +461,32 @@ check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap"); check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap"); - + gr.erase(n1); - + if (nrmap[n0] == 1) nrmap.swap(n0, n2); nrmap.swap(n2, n0); if (armap[a1] == 1) armap.swap(a1, a3); armap.swap(a3, a1); - + check(nrmap.size() == 2 && armap.size() == 2, "Wrong RangeIdMap::size()"); check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap"); check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap"); - + check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap"); check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap"); check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap"); } - + // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap { typedef ListGraph Graph; GRAPH_TYPEDEFS(Graph); - + checkConcept, SourceMap >(); checkConcept, TargetMap >(); checkConcept, ForwardMap >(); @@ -497,19 +498,19 @@ Node n0 = gr.addNode(); Node n1 = gr.addNode(); Node n2 = gr.addNode(); - + gr.addEdge(n0,n1); gr.addEdge(n1,n2); gr.addEdge(n0,n2); gr.addEdge(n2,n1); gr.addEdge(n1,n2); gr.addEdge(n0,n1); - + for (EdgeIt e(gr); e != INVALID; ++e) { check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap"); check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap"); } - + check(mapCompare(gr, sourceMap(orienter(gr, constMap(true))), targetMap(orienter(gr, constMap(false)))), @@ -519,16 +520,16 @@ Digraph dgr(gr, constMap(true)); OutDegMap odm(dgr); InDegMap idm(dgr); - + check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap"); check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); - + gr.addEdge(n2, n0); check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap"); check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); } - + // CrossRefMap { typedef ListDigraph Graph; @@ -540,19 +541,19 @@ CrossRefMap >(); checkConcept, CrossRefMap >(); - + Graph gr; typedef CrossRefMap CRMap; CRMap map(gr); - + Node n0 = gr.addNode(); Node n1 = gr.addNode(); Node n2 = gr.addNode(); - + map.set(n0, 'A'); map.set(n1, 'B'); map.set(n2, 'C'); - + check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap"); check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1, @@ -561,11 +562,11 @@ "Wrong CrossRefMap"); check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1, "Wrong CrossRefMap::count()"); - + CRMap::ValueIt it = map.beginValue(); check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && it == map.endValue(), "Wrong value iterator"); - + map.set(n2, 'A'); check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A', @@ -603,16 +604,16 @@ checkConcept, CrossRefMap >(); - + Graph gr; typedef CrossRefMap CRMap; typedef CRMap::ValueIterator ValueIt; CRMap map(gr); - + Node n0 = gr.addNode(); Node n1 = gr.addNode(); Node n2 = gr.addNode(); - + map.set(n0, 'A'); map.set(n1, 'B'); map.set(n2, 'C'); @@ -629,7 +630,7 @@ check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && it == map.endValue(), "Wrong value iterator"); } - + // Iterable bool map { typedef SmartGraph Graph; @@ -817,7 +818,7 @@ check(n == num, "Wrong number"); } - + // Graph map utilities: // mapMin(), mapMax(), mapMinValue(), mapMaxValue() // mapFind(), mapFindIf(), mapCount(), mapCountIf() @@ -829,16 +830,16 @@ Node n1 = g.addNode(); Node n2 = g.addNode(); Node n3 = g.addNode(); - + SmartDigraph::NodeMap map1(g); SmartDigraph::ArcMap map2(g); ConstMap cmap1 = A(); ConstMap cmap2 = C(0); - + map1[n1] = 10; map1[n2] = 5; map1[n3] = 12; - + // mapMin(), mapMax(), mapMinValue(), mapMaxValue() check(mapMin(g, map1) == n2, "Wrong mapMin()"); check(mapMax(g, map1) == n3, "Wrong mapMax()"); @@ -857,7 +858,7 @@ Arc a2 = g.addArc(n1, n3); Arc a3 = g.addArc(n2, n3); Arc a4 = g.addArc(n3, n1); - + map2[a1] = 'b'; map2[a2] = 'a'; map2[a3] = 'b'; @@ -924,7 +925,7 @@ "Wrong mapCountIf()"); check(mapCountIf(g, map2, Less('a')) == 0, "Wrong mapCountIf()"); - + // MapIt, ConstMapIt /* These tests can be used after applying bugfix #330 @@ -934,7 +935,7 @@ "Wrong NodeMap<>::MapIt"); check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12, "Wrong NodeMap<>::MapIt"); - + int sum = 0; std::for_each(MapIt(map1), MapIt(INVALID), Sum(sum)); check(sum == 27, "Wrong NodeMap<>::MapIt"); @@ -951,41 +952,41 @@ SmartDigraph::NodeMap map3(g, 0); SmartDigraph::ArcMap map4(g, 'a'); - + check(!mapCompare(g, map1, map3), "Wrong mapCompare()"); - check(!mapCompare(g, map2, map4), "Wrong mapCompare()"); - + check(!mapCompare(g, map2, map4), "Wrong mapCompare()"); + mapCopy(g, map1, map3); mapCopy(g, map2, map4); check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()"); - check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()"); - + check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()"); + Undirector ug(g); Undirector::EdgeMap umap1(ug, 'x'); Undirector::ArcMap umap2(ug, 3.14); - + check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()"); check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()"); check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); - + mapCopy(g, map2, umap1); check(mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()"); check(mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()"); check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); - + mapCopy(g, map2, umap1); mapCopy(g, umap1, map2); mapCopy(ug, map2, umap1); mapCopy(ug, umap1, map2); - + check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); mapCopy(ug, umap1, umap2); check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); - + check(!mapCompare(g, map1, constMap(2)), "Wrong mapCompare()"); mapFill(g, map1, 2); check(mapCompare(g, constMap(2), map1), "Wrong mapFill()"); @@ -994,6 +995,6 @@ mapCopy(g, constMap('z'), map2); check(mapCompare(g, constMap('z'), map2), "Wrong mapCopy()"); } - + return 0; }