Changeset 693:7bda7860e0a8 in lemon-main for test
- Timestamp:
- 06/27/09 13:07:26 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/maps_test.cc
r477 r693 350 350 } 351 351 352 // Iterable bool map 353 { 354 typedef SmartGraph Graph; 355 typedef SmartGraph::Node Item; 356 357 typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm; 358 checkConcept<ReadWriteMap<Item, int>, Ibm>(); 359 360 const int num = 10; 361 Graph g; 362 std::vector<Item> items; 363 for (int i = 0; i < num; ++i) { 364 items.push_back(g.addNode()); 365 } 366 367 Ibm map1(g, true); 368 int n = 0; 369 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 370 check(map1[static_cast<Item>(it)], "Wrong TrueIt"); 371 ++n; 372 } 373 check(n == num, "Wrong number"); 374 375 n = 0; 376 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) { 377 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true"); 378 ++n; 379 } 380 check(n == num, "Wrong number"); 381 check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt"); 382 check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false"); 383 384 map1[items[5]] = true; 385 386 n = 0; 387 for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) { 388 check(map1[static_cast<Item>(it)], "Wrong ItemIt for true"); 389 ++n; 390 } 391 check(n == num, "Wrong number"); 392 393 map1[items[num / 2]] = false; 394 check(map1[items[num / 2]] == false, "Wrong map value"); 395 396 n = 0; 397 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 398 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true"); 399 ++n; 400 } 401 check(n == num - 1, "Wrong number"); 402 403 n = 0; 404 for (Ibm::FalseIt it(map1); it != INVALID; ++it) { 405 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true"); 406 ++n; 407 } 408 check(n == 1, "Wrong number"); 409 410 map1[items[0]] = false; 411 check(map1[items[0]] == false, "Wrong map value"); 412 413 map1[items[num - 1]] = false; 414 check(map1[items[num - 1]] == false, "Wrong map value"); 415 416 n = 0; 417 for (Ibm::TrueIt it(map1); it != INVALID; ++it) { 418 check(map1[static_cast<Item>(it)], "Wrong TrueIt for true"); 419 ++n; 420 } 421 check(n == num - 3, "Wrong number"); 422 check(map1.trueNum() == num - 3, "Wrong number"); 423 424 n = 0; 425 for (Ibm::FalseIt it(map1); it != INVALID; ++it) { 426 check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true"); 427 ++n; 428 } 429 check(n == 3, "Wrong number"); 430 check(map1.falseNum() == 3, "Wrong number"); 431 } 432 433 // Iterable int map 434 { 435 typedef SmartGraph Graph; 436 typedef SmartGraph::Node Item; 437 typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim; 438 439 checkConcept<ReadWriteMap<Item, int>, Iim>(); 440 441 const int num = 10; 442 Graph g; 443 std::vector<Item> items; 444 for (int i = 0; i < num; ++i) { 445 items.push_back(g.addNode()); 446 } 447 448 Iim map1(g); 449 check(map1.size() == 0, "Wrong size"); 450 451 for (int i = 0; i < num; ++i) { 452 map1[items[i]] = i; 453 } 454 check(map1.size() == num, "Wrong size"); 455 456 for (int i = 0; i < num; ++i) { 457 Iim::ItemIt it(map1, i); 458 check(static_cast<Item>(it) == items[i], "Wrong value"); 459 ++it; 460 check(static_cast<Item>(it) == INVALID, "Wrong value"); 461 } 462 463 for (int i = 0; i < num; ++i) { 464 map1[items[i]] = i % 2; 465 } 466 check(map1.size() == 2, "Wrong size"); 467 468 int n = 0; 469 for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) { 470 check(map1[static_cast<Item>(it)] == 0, "Wrong Value"); 471 ++n; 472 } 473 check(n == (num + 1) / 2, "Wrong number"); 474 475 for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) { 476 check(map1[static_cast<Item>(it)] == 1, "Wrong Value"); 477 ++n; 478 } 479 check(n == num, "Wrong number"); 480 481 } 482 483 // Iterable value map 484 { 485 typedef SmartGraph Graph; 486 typedef SmartGraph::Node Item; 487 typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm; 488 489 checkConcept<ReadWriteMap<Item, double>, Ivm>(); 490 491 const int num = 10; 492 Graph g; 493 std::vector<Item> items; 494 for (int i = 0; i < num; ++i) { 495 items.push_back(g.addNode()); 496 } 497 498 Ivm map1(g, 0.0); 499 check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size"); 500 check(*map1.beginValue() == 0.0, "Wrong value"); 501 502 for (int i = 0; i < num; ++i) { 503 map1.set(items[i], static_cast<double>(i)); 504 } 505 check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size"); 506 507 for (int i = 0; i < num; ++i) { 508 Ivm::ItemIt it(map1, static_cast<double>(i)); 509 check(static_cast<Item>(it) == items[i], "Wrong value"); 510 ++it; 511 check(static_cast<Item>(it) == INVALID, "Wrong value"); 512 } 513 514 for (Ivm::ValueIterator vit = map1.beginValue(); 515 vit != map1.endValue(); ++vit) { 516 check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit, 517 "Wrong ValueIterator"); 518 } 519 520 for (int i = 0; i < num; ++i) { 521 map1.set(items[i], static_cast<double>(i % 2)); 522 } 523 check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size"); 524 525 int n = 0; 526 for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) { 527 check(map1[static_cast<Item>(it)] == 0.0, "Wrong Value"); 528 ++n; 529 } 530 check(n == (num + 1) / 2, "Wrong number"); 531 532 for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) { 533 check(map1[static_cast<Item>(it)] == 1.0, "Wrong Value"); 534 ++n; 535 } 536 check(n == num, "Wrong number"); 537 538 } 352 539 return 0; 353 540 }
Note: See TracChangeset
for help on using the changeset viewer.