Changeset 721:99124ea4f048 in lemon1.2 for test/maps_test.cc
 Timestamp:
 08/02/09 13:44:45 (12 years ago)
 Branch:
 default
 Parents:
 720:6e8c27ee9079 (diff), 694:71939d63ae77 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.  Phase:
 public
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

test/maps_test.cc
r694 r721 23 23 #include <lemon/concepts/maps.h> 24 24 #include <lemon/maps.h> 25 #include <lemon/list_graph.h> 25 26 #include <lemon/smart_graph.h> 26 27 … … 330 331 { 331 332 typedef std::vector<int> vec; 333 checkConcept<WriteMap<int, bool>, LoggerBoolMap<vec::iterator> >(); 334 checkConcept<WriteMap<int, bool>, 335 LoggerBoolMap<std::back_insert_iterator<vec> > >(); 336 332 337 vec v1; 333 338 vec v2(10); … … 350 355 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); 351 356 } 357 358 // IdMap, RangeIdMap 359 { 360 typedef ListDigraph Graph; 361 DIGRAPH_TYPEDEFS(Graph); 362 363 checkConcept<ReadMap<Node, int>, IdMap<Graph, Node> >(); 364 checkConcept<ReadMap<Arc, int>, IdMap<Graph, Arc> >(); 365 checkConcept<ReadMap<Node, int>, RangeIdMap<Graph, Node> >(); 366 checkConcept<ReadMap<Arc, int>, RangeIdMap<Graph, Arc> >(); 367 368 Graph gr; 369 IdMap<Graph, Node> nmap(gr); 370 IdMap<Graph, Arc> amap(gr); 371 RangeIdMap<Graph, Node> nrmap(gr); 372 RangeIdMap<Graph, Arc> armap(gr); 373 374 Node n0 = gr.addNode(); 375 Node n1 = gr.addNode(); 376 Node n2 = gr.addNode(); 377 378 Arc a0 = gr.addArc(n0, n1); 379 Arc a1 = gr.addArc(n0, n2); 380 Arc a2 = gr.addArc(n2, n1); 381 Arc a3 = gr.addArc(n2, n0); 382 383 check(nmap[n0] == gr.id(n0) && nmap(gr.id(n0)) == n0, "Wrong IdMap"); 384 check(nmap[n1] == gr.id(n1) && nmap(gr.id(n1)) == n1, "Wrong IdMap"); 385 check(nmap[n2] == gr.id(n2) && nmap(gr.id(n2)) == n2, "Wrong IdMap"); 386 387 check(amap[a0] == gr.id(a0) && amap(gr.id(a0)) == a0, "Wrong IdMap"); 388 check(amap[a1] == gr.id(a1) && amap(gr.id(a1)) == a1, "Wrong IdMap"); 389 check(amap[a2] == gr.id(a2) && amap(gr.id(a2)) == a2, "Wrong IdMap"); 390 check(amap[a3] == gr.id(a3) && amap(gr.id(a3)) == a3, "Wrong IdMap"); 391 392 check(nmap.inverse()[gr.id(n0)] == n0, "Wrong IdMap::InverseMap"); 393 check(amap.inverse()[gr.id(a0)] == a0, "Wrong IdMap::InverseMap"); 394 395 check(nrmap.size() == 3 && armap.size() == 4, 396 "Wrong RangeIdMap::size()"); 397 398 check(nrmap[n0] == 0 && nrmap(0) == n0, "Wrong RangeIdMap"); 399 check(nrmap[n1] == 1 && nrmap(1) == n1, "Wrong RangeIdMap"); 400 check(nrmap[n2] == 2 && nrmap(2) == n2, "Wrong RangeIdMap"); 401 402 check(armap[a0] == 0 && armap(0) == a0, "Wrong RangeIdMap"); 403 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); 404 check(armap[a2] == 2 && armap(2) == a2, "Wrong RangeIdMap"); 405 check(armap[a3] == 3 && armap(3) == a3, "Wrong RangeIdMap"); 406 407 check(nrmap.inverse()[0] == n0, "Wrong RangeIdMap::InverseMap"); 408 check(armap.inverse()[0] == a0, "Wrong RangeIdMap::InverseMap"); 409 410 gr.erase(n1); 411 412 if (nrmap[n0] == 1) nrmap.swap(n0, n2); 413 nrmap.swap(n2, n0); 414 if (armap[a1] == 1) armap.swap(a1, a3); 415 armap.swap(a3, a1); 416 417 check(nrmap.size() == 2 && armap.size() == 2, 418 "Wrong RangeIdMap::size()"); 419 420 check(nrmap[n0] == 1 && nrmap(1) == n0, "Wrong RangeIdMap"); 421 check(nrmap[n2] == 0 && nrmap(0) == n2, "Wrong RangeIdMap"); 422 423 check(armap[a1] == 1 && armap(1) == a1, "Wrong RangeIdMap"); 424 check(armap[a3] == 0 && armap(0) == a3, "Wrong RangeIdMap"); 425 426 check(nrmap.inverse()[0] == n2, "Wrong RangeIdMap::InverseMap"); 427 check(armap.inverse()[0] == a3, "Wrong RangeIdMap::InverseMap"); 428 } 429 430 // CrossRefMap 431 { 432 typedef ListDigraph Graph; 433 DIGRAPH_TYPEDEFS(Graph); 434 435 checkConcept<ReadWriteMap<Node, int>, 436 CrossRefMap<Graph, Node, int> >(); 437 checkConcept<ReadWriteMap<Node, bool>, 438 CrossRefMap<Graph, Node, bool> >(); 439 checkConcept<ReadWriteMap<Node, double>, 440 CrossRefMap<Graph, Node, double> >(); 441 442 Graph gr; 443 typedef CrossRefMap<Graph, Node, char> CRMap; 444 typedef CRMap::ValueIterator ValueIt; 445 CRMap map(gr); 446 447 Node n0 = gr.addNode(); 448 Node n1 = gr.addNode(); 449 Node n2 = gr.addNode(); 450 451 map.set(n0, 'A'); 452 map.set(n1, 'B'); 453 map.set(n2, 'C'); 454 455 check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0, 456 "Wrong CrossRefMap"); 457 check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1, 458 "Wrong CrossRefMap"); 459 check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2, 460 "Wrong CrossRefMap"); 461 check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1, 462 "Wrong CrossRefMap::count()"); 463 464 ValueIt it = map.beginValue(); 465 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && 466 it == map.endValue(), "Wrong value iterator"); 467 468 map.set(n2, 'A'); 469 470 check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A', 471 "Wrong CrossRefMap"); 472 check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap"); 473 check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap"); 474 check(map('C') == INVALID && map.inverse()['C'] == INVALID, 475 "Wrong CrossRefMap"); 476 check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0, 477 "Wrong CrossRefMap::count()"); 478 479 it = map.beginValue(); 480 check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' && 481 it == map.endValue(), "Wrong value iterator"); 482 483 map.set(n0, 'C'); 484 485 check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A', 486 "Wrong CrossRefMap"); 487 check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap"); 488 check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap"); 489 check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap"); 490 check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1, 491 "Wrong CrossRefMap::count()"); 492 493 it = map.beginValue(); 494 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && 495 it == map.endValue(), "Wrong value iterator"); 496 } 352 497 353 498 // Iterable bool map 
test/maps_test.cc
r720 r721 24 24 #include <lemon/maps.h> 25 25 #include <lemon/list_graph.h> 26 #include <lemon/smart_graph.h> 26 27 27 28 #include "test_tools.h" … … 495 496 } 496 497 498 // Iterable bool map 499 { 500 typedef SmartGraph Graph; 501 typedef SmartGraph::Node Item; 502 503 typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm; 504 checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>(); 505 506 const int num = 10; 507 Graph g; 508 std::vector<Item> items; 509 for (int i = 0; i < num; ++i) { 510 items.push_back(g.addNode()); 511 } 512 513 Ibm map1(g, true); 514 int n = 0; 515 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 516 check(map1[static_cast<Item>(it)], "Wrong TrueIt"); 517 ++n; 518 } 519 check(n == num, "Wrong number"); 520 521 n = 0; 522 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) { 523 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true"); 524 ++n; 525 } 526 check(n == num, "Wrong number"); 527 check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt"); 528 check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false"); 529 530 map1[items[5]] = true; 531 532 n = 0; 533 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) { 534 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true"); 535 ++n; 536 } 537 check(n == num, "Wrong number"); 538 539 map1[items[num / 2]] = false; 540 check(map1[items[num / 2]] == false, "Wrong map value"); 541 542 n = 0; 543 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 544 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true"); 545 ++n; 546 } 547 check(n == num  1, "Wrong number"); 548 549 n = 0; 550 for (Ibm::FalseIt it(map1); it != INVALID; ++it) { 551 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true"); 552 ++n; 553 } 554 check(n == 1, "Wrong number"); 555 556 map1[items[0]] = false; 557 check(map1[items[0]] == false, "Wrong map value"); 558 559 map1[items[num  1]] = false; 560 check(map1[items[num  1]] == false, "Wrong map value"); 561 562 n = 0; 563 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 564 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true"); 565 ++n; 566 } 567 check(n == num  3, "Wrong number"); 568 check(map1.trueNum() == num  3, "Wrong number"); 569 570 n = 0; 571 for (Ibm::FalseIt it(map1); it != INVALID; ++it) { 572 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true"); 573 ++n; 574 } 575 check(n == 3, "Wrong number"); 576 check(map1.falseNum() == 3, "Wrong number"); 577 } 578 579 // Iterable int map 580 { 581 typedef SmartGraph Graph; 582 typedef SmartGraph::Node Item; 583 typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim; 584 585 checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>(); 586 587 const int num = 10; 588 Graph g; 589 std::vector<Item> items; 590 for (int i = 0; i < num; ++i) { 591 items.push_back(g.addNode()); 592 } 593 594 Iim map1(g); 595 check(map1.size() == 0, "Wrong size"); 596 597 for (int i = 0; i < num; ++i) { 598 map1[items[i]] = i; 599 } 600 check(map1.size() == num, "Wrong size"); 601 602 for (int i = 0; i < num; ++i) { 603 Iim::ItemIt it(map1, i); 604 check(static_cast<Item>(it) == items[i], "Wrong value"); 605 ++it; 606 check(static_cast<Item>(it) == INVALID, "Wrong value"); 607 } 608 609 for (int i = 0; i < num; ++i) { 610 map1[items[i]] = i % 2; 611 } 612 check(map1.size() == 2, "Wrong size"); 613 614 int n = 0; 615 for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) { 616 check(map1[static_cast<Item>(it)] == 0, "Wrong value"); 617 ++n; 618 } 619 check(n == (num + 1) / 2, "Wrong number"); 620 621 for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) { 622 check(map1[static_cast<Item>(it)] == 1, "Wrong value"); 623 ++n; 624 } 625 check(n == num, "Wrong number"); 626 627 } 628 629 // Iterable value map 630 { 631 typedef SmartGraph Graph; 632 typedef SmartGraph::Node Item; 633 typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm; 634 635 checkConcept<ReadWriteMap<Item, double>, Ivm>(); 636 637 const int num = 10; 638 Graph g; 639 std::vector<Item> items; 640 for (int i = 0; i < num; ++i) { 641 items.push_back(g.addNode()); 642 } 643 644 Ivm map1(g, 0.0); 645 check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size"); 646 check(*map1.beginValue() == 0.0, "Wrong value"); 647 648 for (int i = 0; i < num; ++i) { 649 map1.set(items[i], static_cast<double>(i)); 650 } 651 check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size"); 652 653 for (int i = 0; i < num; ++i) { 654 Ivm::ItemIt it(map1, static_cast<double>(i)); 655 check(static_cast<Item>(it) == items[i], "Wrong value"); 656 ++it; 657 check(static_cast<Item>(it) == INVALID, "Wrong value"); 658 } 659 660 for (Ivm::ValueIterator vit = map1.beginValue(); 661 vit != map1.endValue(); ++vit) { 662 check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit, 663 "Wrong ValueIterator"); 664 } 665 666 for (int i = 0; i < num; ++i) { 667 map1.set(items[i], static_cast<double>(i % 2)); 668 } 669 check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size"); 670 671 int n = 0; 672 for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) { 673 check(map1[static_cast<Item>(it)] == 0.0, "Wrong value"); 674 ++n; 675 } 676 check(n == (num + 1) / 2, "Wrong number"); 677 678 for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) { 679 check(map1[static_cast<Item>(it)] == 1.0, "Wrong value"); 680 ++n; 681 } 682 check(n == num, "Wrong number"); 683 684 } 497 685 return 0; 498 686 }
Note: See TracChangeset
for help on using the changeset viewer.