Changeset 956:141f9c0db4a3 in lemon for test/maps_test.cc
 Timestamp:
 03/06/10 15:35:12 (10 years ago)
 Branch:
 default
 Children:
 957:f802439d2b58, 959:38213abd2911, 1041:f112c18bc304
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

test/maps_test.cc
r836 r956 3 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 200320 095 * Copyright (C) 20032010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 226 226 227 227 checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); 228 MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>()); 228 MapToFunctor<ReadMap<A,B> > map = 229 MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>()); 229 230 230 231 check(functorToMap(&func)[A()] == 3, … … 378 379 it != map2.end(); ++it ) 379 380 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); 380 381 381 382 typedef ListDigraph Graph; 382 383 DIGRAPH_TYPEDEFS(Graph); … … 387 388 Node n2 = gr.addNode(); 388 389 Node n3 = gr.addNode(); 389 390 390 391 gr.addArc(n3, n0); 391 392 gr.addArc(n3, n2); … … 393 394 gr.addArc(n2, n1); 394 395 gr.addArc(n0, n1); 395 396 396 397 { 397 398 std::vector<Node> v; … … 404 405 std::vector<Node> v(countNodes(gr)); 405 406 dfs(gr).processedMap(loggerBoolMap(v.begin())).run(); 406 407 407 408 check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3, 408 409 "Something is wrong with LoggerBoolMap"); 409 410 } 410 411 } 411 412 412 413 // IdMap, RangeIdMap 413 414 { … … 419 420 checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >(); 420 421 checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >(); 421 422 422 423 Graph gr; 423 424 IdMap<Graph, Node> nmap(gr); … … 425 426 RangeIdMap<Graph, Node> nrmap(gr); 426 427 RangeIdMap<Graph, Arc> armap(gr); 427 428 428 429 Node n0 = gr.addNode(); 429 430 Node n1 = gr.addNode(); 430 431 Node n2 = gr.addNode(); 431 432 432 433 Arc a0 = gr.addArc(n0, n1); 433 434 Arc a1 = gr.addArc(n0, n2); 434 435 Arc a2 = gr.addArc(n2, n1); 435 436 Arc a3 = gr.addArc(n2, n0); 436 437 437 438 check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap"); 438 439 check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap"); … … 446 447 check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap"); 447 448 check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap"); 448 449 449 450 check(nrmap.size() == 3 && armap.size() == 4, 450 451 "Wrong RangeIdMap::size()"); … … 453 454 check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap"); 454 455 check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap"); 455 456 456 457 check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap"); 457 458 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); … … 461 462 check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap"); 462 463 check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap"); 463 464 464 465 gr.erase(n1); 465 466 466 467 if (nrmap[n0] == 1) nrmap.swap(n0, n2); 467 468 nrmap.swap(n2, n0); 468 469 if (armap[a1] == 1) armap.swap(a1, a3); 469 470 armap.swap(a3, a1); 470 471 471 472 check(nrmap.size() == 2 && armap.size() == 2, 472 473 "Wrong RangeIdMap::size()"); … … 474 475 check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap"); 475 476 check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap"); 476 477 477 478 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); 478 479 check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap"); … … 481 482 check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap"); 482 483 } 483 484 484 485 // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap 485 486 { 486 487 typedef ListGraph Graph; 487 488 GRAPH_TYPEDEFS(Graph); 488 489 489 490 checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >(); 490 491 checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >(); … … 498 499 Node n1 = gr.addNode(); 499 500 Node n2 = gr.addNode(); 500 501 501 502 gr.addEdge(n0,n1); 502 503 gr.addEdge(n1,n2); … … 505 506 gr.addEdge(n1,n2); 506 507 gr.addEdge(n0,n1); 507 508 508 509 for (EdgeIt e(gr); e != INVALID; ++e) { 509 510 check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap"); 510 511 check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap"); 511 512 } 512 513 513 514 check(mapCompare(gr, 514 515 sourceMap(orienter(gr, constMap<Edge, bool>(true))), … … 520 521 OutDegMap<Digraph> odm(dgr); 521 522 InDegMap<Digraph> idm(dgr); 522 523 523 524 check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap"); 524 525 check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); 525 526 526 527 gr.addEdge(n2, n0); 527 528 … … 529 530 check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); 530 531 } 531 532 532 533 // CrossRefMap 533 534 { … … 541 542 checkConcept<ReadWriteMap<Node, double>, 542 543 CrossRefMap<Graph, Node, double> >(); 543 544 544 545 Graph gr; 545 546 typedef CrossRefMap<Graph, Node, char> CRMap; 546 547 CRMap map(gr); 547 548 548 549 Node n0 = gr.addNode(); 549 550 Node n1 = gr.addNode(); 550 551 Node n2 = gr.addNode(); 551 552 552 553 map.set(n0, 'A'); 553 554 map.set(n1, 'B'); 554 555 map.set(n2, 'C'); 555 556 556 557 check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0, 557 558 "Wrong CrossRefMap"); … … 562 563 check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1, 563 564 "Wrong CrossRefMap::count()"); 564 565 565 566 CRMap::ValueIt it = map.beginValue(); 566 567 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && 567 568 it == map.endValue(), "Wrong value iterator"); 568 569 569 570 map.set(n2, 'A'); 570 571 … … 604 605 checkConcept<ReadWriteMap<Node, int>, 605 606 CrossRefMap<Graph, Node, int> >(); 606 607 607 608 Graph gr; 608 609 typedef CrossRefMap<Graph, Node, char> CRMap; 609 610 typedef CRMap::ValueIterator ValueIt; 610 611 CRMap map(gr); 611 612 612 613 Node n0 = gr.addNode(); 613 614 Node n1 = gr.addNode(); 614 615 Node n2 = gr.addNode(); 615 616 616 617 map.set(n0, 'A'); 617 618 map.set(n1, 'B'); … … 630 631 it == map.endValue(), "Wrong value iterator"); 631 632 } 632 633 633 634 // Iterable bool map 634 635 { … … 818 819 819 820 } 820 821 821 822 // Graph map utilities: 822 823 // mapMin(), mapMax(), mapMinValue(), mapMaxValue() … … 830 831 Node n2 = g.addNode(); 831 832 Node n3 = g.addNode(); 832 833 833 834 SmartDigraph::NodeMap<int> map1(g); 834 835 SmartDigraph::ArcMap<char> map2(g); 835 836 ConstMap<Node, A> cmap1 = A(); 836 837 ConstMap<Arc, C> cmap2 = C(0); 837 838 838 839 map1[n1] = 10; 839 840 map1[n2] = 5; 840 841 map1[n3] = 12; 841 842 842 843 // mapMin(), mapMax(), mapMinValue(), mapMaxValue() 843 844 check(mapMin(g, map1) == n2, "Wrong mapMin()"); … … 858 859 Arc a3 = g.addArc(n2, n3); 859 860 Arc a4 = g.addArc(n3, n1); 860 861 861 862 map2[a1] = 'b'; 862 863 map2[a2] = 'a'; … … 925 926 check(mapCountIf(g, map2, Less<char>('a')) == 0, 926 927 "Wrong mapCountIf()"); 927 928 928 929 // MapIt, ConstMapIt 929 930 /* … … 935 936 check(*std::max_element(ConstMapIt(map1), ConstMapIt(INVALID)) == 12, 936 937 "Wrong NodeMap<>::MapIt"); 937 938 938 939 int sum = 0; 939 940 std::for_each(MapIt(map1), MapIt(INVALID), Sum<int>(sum)); … … 952 953 SmartDigraph::NodeMap<int> map3(g, 0); 953 954 SmartDigraph::ArcMap<char> map4(g, 'a'); 954 955 955 956 check(!mapCompare(g, map1, map3), "Wrong mapCompare()"); 956 check(!mapCompare(g, map2, map4), "Wrong mapCompare()"); 957 957 check(!mapCompare(g, map2, map4), "Wrong mapCompare()"); 958 958 959 mapCopy(g, map1, map3); 959 960 mapCopy(g, map2, map4); 960 961 961 962 check(mapCompare(g, map1, map3), "Wrong mapCompare() or mapCopy()"); 962 check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()"); 963 963 check(mapCompare(g, map2, map4), "Wrong mapCompare() or mapCopy()"); 964 964 965 Undirector<SmartDigraph> ug(g); 965 966 Undirector<SmartDigraph>::EdgeMap<char> umap1(ug, 'x'); 966 967 Undirector<SmartDigraph>::ArcMap<double> umap2(ug, 3.14); 967 968 968 969 check(!mapCompare(g, map2, umap1), "Wrong mapCompare() or mapCopy()"); 969 970 check(!mapCompare(g, umap1, map2), "Wrong mapCompare() or mapCopy()"); 970 971 check(!mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); 971 972 check(!mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); 972 973 973 974 mapCopy(g, map2, umap1); 974 975 … … 977 978 check(mapCompare(ug, map2, umap1), "Wrong mapCompare() or mapCopy()"); 978 979 check(mapCompare(ug, umap1, map2), "Wrong mapCompare() or mapCopy()"); 979 980 980 981 mapCopy(g, map2, umap1); 981 982 mapCopy(g, umap1, map2); 982 983 mapCopy(ug, map2, umap1); 983 984 mapCopy(ug, umap1, map2); 984 985 985 986 check(!mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); 986 987 mapCopy(ug, umap1, umap2); 987 988 check(mapCompare(ug, umap1, umap2), "Wrong mapCompare() or mapCopy()"); 988 989 989 990 check(!mapCompare(g, map1, constMap<Node>(2)), "Wrong mapCompare()"); 990 991 mapFill(g, map1, 2); … … 995 996 check(mapCompare(g, constMap<Arc>('z'), map2), "Wrong mapCopy()"); 996 997 } 997 998 998 999 return 0; 999 1000 }
Note: See TracChangeset
for help on using the changeset viewer.