Changeset 695:8dae88c5943e in lemon-main for test
- Timestamp:
- 08/31/09 08:25:33 (15 years ago)
- Branch:
- default
- Parents:
- 692:33f417de9e70 (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
r684 r695 23 23 #include <lemon/concepts/maps.h> 24 24 #include <lemon/maps.h> 25 #include <lemon/ list_graph.h>25 #include <lemon/smart_graph.h> 26 26 27 27 #include "test_tools.h" … … 350 350 check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); 351 351 } 352 352 353 353 // CrossRefMap 354 354 { 355 typedef ListDigraph Graph;355 typedef SmartDigraph Graph; 356 356 DIGRAPH_TYPEDEFS(Graph); 357 357 … … 384 384 it == map.endValue(), "Wrong value iterator"); 385 385 } 386 386 387 // Iterable bool map 388 { 389 typedef SmartGraph Graph; 390 typedef SmartGraph::Node Item; 391 392 typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm; 393 checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>(); 394 395 const int num = 10; 396 Graph g; 397 std::vector<Item> items; 398 for (int i = 0; i < num; ++i) { 399 items.push_back(g.addNode()); 400 } 401 402 Ibm map1(g, true); 403 int n = 0; 404 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 405 check(map1[static_cast<Item>(it)], "Wrong TrueIt"); 406 ++n; 407 } 408 check(n == num, "Wrong number"); 409 410 n = 0; 411 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) { 412 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true"); 413 ++n; 414 } 415 check(n == num, "Wrong number"); 416 check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt"); 417 check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false"); 418 419 map1[items[5]] = true; 420 421 n = 0; 422 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) { 423 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true"); 424 ++n; 425 } 426 check(n == num, "Wrong number"); 427 428 map1[items[num / 2]] = false; 429 check(map1[items[num / 2]] == false, "Wrong map value"); 430 431 n = 0; 432 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 433 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true"); 434 ++n; 435 } 436 check(n == num - 1, "Wrong number"); 437 438 n = 0; 439 for (Ibm::FalseIt it(map1); it != INVALID; ++it) { 440 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true"); 441 ++n; 442 } 443 check(n == 1, "Wrong number"); 444 445 map1[items[0]] = false; 446 check(map1[items[0]] == false, "Wrong map value"); 447 448 map1[items[num - 1]] = false; 449 check(map1[items[num - 1]] == false, "Wrong map value"); 450 451 n = 0; 452 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 453 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true"); 454 ++n; 455 } 456 check(n == num - 3, "Wrong number"); 457 check(map1.trueNum() == num - 3, "Wrong number"); 458 459 n = 0; 460 for (Ibm::FalseIt it(map1); it != INVALID; ++it) { 461 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true"); 462 ++n; 463 } 464 check(n == 3, "Wrong number"); 465 check(map1.falseNum() == 3, "Wrong number"); 466 } 467 468 // Iterable int map 469 { 470 typedef SmartGraph Graph; 471 typedef SmartGraph::Node Item; 472 typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim; 473 474 checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>(); 475 476 const int num = 10; 477 Graph g; 478 std::vector<Item> items; 479 for (int i = 0; i < num; ++i) { 480 items.push_back(g.addNode()); 481 } 482 483 Iim map1(g); 484 check(map1.size() == 0, "Wrong size"); 485 486 for (int i = 0; i < num; ++i) { 487 map1[items[i]] = i; 488 } 489 check(map1.size() == num, "Wrong size"); 490 491 for (int i = 0; i < num; ++i) { 492 Iim::ItemIt it(map1, i); 493 check(static_cast<Item>(it) == items[i], "Wrong value"); 494 ++it; 495 check(static_cast<Item>(it) == INVALID, "Wrong value"); 496 } 497 498 for (int i = 0; i < num; ++i) { 499 map1[items[i]] = i % 2; 500 } 501 check(map1.size() == 2, "Wrong size"); 502 503 int n = 0; 504 for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) { 505 check(map1[static_cast<Item>(it)] == 0, "Wrong value"); 506 ++n; 507 } 508 check(n == (num + 1) / 2, "Wrong number"); 509 510 for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) { 511 check(map1[static_cast<Item>(it)] == 1, "Wrong value"); 512 ++n; 513 } 514 check(n == num, "Wrong number"); 515 516 } 517 518 // Iterable value map 519 { 520 typedef SmartGraph Graph; 521 typedef SmartGraph::Node Item; 522 typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm; 523 524 checkConcept<ReadWriteMap<Item, double>, Ivm>(); 525 526 const int num = 10; 527 Graph g; 528 std::vector<Item> items; 529 for (int i = 0; i < num; ++i) { 530 items.push_back(g.addNode()); 531 } 532 533 Ivm map1(g, 0.0); 534 check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size"); 535 check(*map1.beginValue() == 0.0, "Wrong value"); 536 537 for (int i = 0; i < num; ++i) { 538 map1.set(items[i], static_cast<double>(i)); 539 } 540 check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size"); 541 542 for (int i = 0; i < num; ++i) { 543 Ivm::ItemIt it(map1, static_cast<double>(i)); 544 check(static_cast<Item>(it) == items[i], "Wrong value"); 545 ++it; 546 check(static_cast<Item>(it) == INVALID, "Wrong value"); 547 } 548 549 for (Ivm::ValueIterator vit = map1.beginValue(); 550 vit != map1.endValue(); ++vit) { 551 check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit, 552 "Wrong ValueIterator"); 553 } 554 555 for (int i = 0; i < num; ++i) { 556 map1.set(items[i], static_cast<double>(i % 2)); 557 } 558 check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size"); 559 560 int n = 0; 561 for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) { 562 check(map1[static_cast<Item>(it)] == 0.0, "Wrong value"); 563 ++n; 564 } 565 check(n == (num + 1) / 2, "Wrong number"); 566 567 for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) { 568 check(map1[static_cast<Item>(it)] == 1.0, "Wrong value"); 569 ++n; 570 } 571 check(n == num, "Wrong number"); 572 573 } 387 574 return 0; 388 575 } -
test/maps_test.cc
r694 r695 351 351 } 352 352 353 // CrossRefMap 354 { 355 typedef SmartDigraph Graph; 356 DIGRAPH_TYPEDEFS(Graph); 357 358 checkConcept<ReadWriteMap<Node, int>, 359 CrossRefMap<Graph, Node, int> >(); 360 361 Graph gr; 362 typedef CrossRefMap<Graph, Node, char> CRMap; 363 typedef CRMap::ValueIterator ValueIt; 364 CRMap map(gr); 365 366 Node n0 = gr.addNode(); 367 Node n1 = gr.addNode(); 368 Node n2 = gr.addNode(); 369 370 map.set(n0, 'A'); 371 map.set(n1, 'B'); 372 map.set(n2, 'C'); 373 map.set(n2, 'A'); 374 map.set(n0, 'C'); 375 376 check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A', 377 "Wrong CrossRefMap"); 378 check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap"); 379 check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap"); 380 check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap"); 381 382 ValueIt it = map.beginValue(); 383 check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && 384 it == map.endValue(), "Wrong value iterator"); 385 } 386 353 387 // Iterable bool map 354 388 {
Note: See TracChangeset
for help on using the changeset viewer.