Changeset 770:acdd0bd75a55 in lemon for test/maps_test.cc
 Timestamp:
 09/25/09 12:12:37 (15 years ago)
 Branch:
 default
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

test/maps_test.cc
r768 r770 25 25 #include <lemon/list_graph.h> 26 26 #include <lemon/smart_graph.h> 27 #include <lemon/adaptors.h> 28 #include <lemon/dfs.h> 27 29 28 30 #include "test_tools.h" … … 62 64 typedef ReadWriteMap<A, bool> BoolWriteMap; 63 65 typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap; 66 67 template<typename Map1, typename Map2, typename ItemIt> 68 void compareMap(const Map1& map1, const Map2& map2, ItemIt it) { 69 for (; it != INVALID; ++it) 70 check(map1[it] == map2[it], "The maps are not equal"); 71 } 64 72 65 73 int main() … … 354 362 it != map2.end(); ++it ) 355 363 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); 364 365 typedef ListDigraph Graph; 366 DIGRAPH_TYPEDEFS(Graph); 367 Graph gr; 368 369 Node n0 = gr.addNode(); 370 Node n1 = gr.addNode(); 371 Node n2 = gr.addNode(); 372 Node n3 = gr.addNode(); 373 374 gr.addArc(n3, n0); 375 gr.addArc(n3, n2); 376 gr.addArc(n0, n2); 377 gr.addArc(n2, n1); 378 gr.addArc(n0, n1); 379 380 { 381 std::vector<Node> v; 382 dfs(gr).processedMap(loggerBoolMap(std::back_inserter(v))).run(); 383 384 check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3, 385 "Something is wrong with LoggerBoolMap"); 386 } 387 { 388 std::vector<Node> v(countNodes(gr)); 389 dfs(gr).processedMap(loggerBoolMap(v.begin())).run(); 390 391 check(v.size()==4 && v[0]==n1 && v[1]==n2 && v[2]==n0 && v[3]==n3, 392 "Something is wrong with LoggerBoolMap"); 393 } 356 394 } 357 395 … … 426 464 check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap"); 427 465 check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap"); 466 } 467 468 // SourceMap, TargetMap, ForwardMap, BackwardMap, InDegMap, OutDegMap 469 { 470 typedef ListGraph Graph; 471 GRAPH_TYPEDEFS(Graph); 472 473 checkConcept<ReadMap<Arc, Node>, SourceMap<Graph> >(); 474 checkConcept<ReadMap<Arc, Node>, TargetMap<Graph> >(); 475 checkConcept<ReadMap<Edge, Arc>, ForwardMap<Graph> >(); 476 checkConcept<ReadMap<Edge, Arc>, BackwardMap<Graph> >(); 477 checkConcept<ReadMap<Node, int>, InDegMap<Graph> >(); 478 checkConcept<ReadMap<Node, int>, OutDegMap<Graph> >(); 479 480 Graph gr; 481 Node n0 = gr.addNode(); 482 Node n1 = gr.addNode(); 483 Node n2 = gr.addNode(); 484 485 gr.addEdge(n0,n1); 486 gr.addEdge(n1,n2); 487 gr.addEdge(n0,n2); 488 gr.addEdge(n2,n1); 489 gr.addEdge(n1,n2); 490 gr.addEdge(n0,n1); 491 492 for (EdgeIt e(gr); e != INVALID; ++e) { 493 check(forwardMap(gr)[e] == gr.direct(e, true), "Wrong ForwardMap"); 494 check(backwardMap(gr)[e] == gr.direct(e, false), "Wrong BackwardMap"); 495 } 496 497 compareMap(sourceMap(orienter(gr, constMap<Edge, bool>(true))), 498 targetMap(orienter(gr, constMap<Edge, bool>(false))), 499 EdgeIt(gr)); 500 501 typedef Orienter<Graph, const ConstMap<Edge, bool> > Digraph; 502 Digraph dgr(gr, constMap<Edge, bool>(true)); 503 OutDegMap<Digraph> odm(dgr); 504 InDegMap<Digraph> idm(dgr); 505 506 check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 1, "Wrong OutDegMap"); 507 check(idm[n0] == 0 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); 508 509 gr.addEdge(n2, n0); 510 511 check(odm[n0] == 3 && odm[n1] == 2 && odm[n2] == 2, "Wrong OutDegMap"); 512 check(idm[n0] == 1 && idm[n1] == 3 && idm[n2] == 3, "Wrong InDegMap"); 428 513 } 429 514
Note: See TracChangeset
for help on using the changeset viewer.