... |
... |
@@ -548,323 +548,326 @@
|
548 |
548 |
|
549 |
549 |
Node n0 = gr.addNode();
|
550 |
550 |
Node n1 = gr.addNode();
|
551 |
551 |
Node n2 = gr.addNode();
|
552 |
552 |
|
553 |
553 |
map.set(n0, 'A');
|
554 |
554 |
map.set(n1, 'B');
|
555 |
555 |
map.set(n2, 'C');
|
556 |
556 |
|
557 |
557 |
check(map[n0] == 'A' && map('A') == n0 && map.inverse()['A'] == n0,
|
558 |
558 |
"Wrong CrossRefMap");
|
559 |
559 |
check(map[n1] == 'B' && map('B') == n1 && map.inverse()['B'] == n1,
|
560 |
560 |
"Wrong CrossRefMap");
|
561 |
561 |
check(map[n2] == 'C' && map('C') == n2 && map.inverse()['C'] == n2,
|
562 |
562 |
"Wrong CrossRefMap");
|
563 |
563 |
check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
|
564 |
564 |
"Wrong CrossRefMap::count()");
|
565 |
565 |
|
566 |
566 |
CRMap::ValueIt it = map.beginValue();
|
567 |
567 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
|
568 |
568 |
it == map.endValue(), "Wrong value iterator");
|
569 |
569 |
|
570 |
570 |
map.set(n2, 'A');
|
571 |
571 |
|
572 |
572 |
check(map[n0] == 'A' && map[n1] == 'B' && map[n2] == 'A',
|
573 |
573 |
"Wrong CrossRefMap");
|
574 |
574 |
check(map('A') == n0 && map.inverse()['A'] == n0, "Wrong CrossRefMap");
|
575 |
575 |
check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
|
576 |
576 |
check(map('C') == INVALID && map.inverse()['C'] == INVALID,
|
577 |
577 |
"Wrong CrossRefMap");
|
578 |
578 |
check(map.count('A') == 2 && map.count('B') == 1 && map.count('C') == 0,
|
579 |
579 |
"Wrong CrossRefMap::count()");
|
580 |
580 |
|
581 |
581 |
it = map.beginValue();
|
582 |
582 |
check(*it++ == 'A' && *it++ == 'A' && *it++ == 'B' &&
|
583 |
583 |
it == map.endValue(), "Wrong value iterator");
|
584 |
584 |
|
585 |
585 |
map.set(n0, 'C');
|
586 |
586 |
|
587 |
587 |
check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
|
588 |
588 |
"Wrong CrossRefMap");
|
589 |
589 |
check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
|
590 |
590 |
check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
|
591 |
591 |
check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
|
592 |
592 |
check(map.count('A') == 1 && map.count('B') == 1 && map.count('C') == 1,
|
593 |
593 |
"Wrong CrossRefMap::count()");
|
594 |
594 |
|
595 |
595 |
it = map.beginValue();
|
596 |
596 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
|
597 |
597 |
it == map.endValue(), "Wrong value iterator");
|
598 |
598 |
}
|
599 |
599 |
|
600 |
600 |
// CrossRefMap
|
601 |
601 |
{
|
602 |
602 |
typedef SmartDigraph Graph;
|
603 |
603 |
DIGRAPH_TYPEDEFS(Graph);
|
604 |
604 |
|
605 |
605 |
checkConcept<ReadWriteMap<Node, int>,
|
606 |
606 |
CrossRefMap<Graph, Node, int> >();
|
607 |
607 |
|
608 |
608 |
Graph gr;
|
609 |
609 |
typedef CrossRefMap<Graph, Node, char> CRMap;
|
610 |
610 |
typedef CRMap::ValueIterator ValueIt;
|
611 |
611 |
CRMap map(gr);
|
612 |
612 |
|
613 |
613 |
Node n0 = gr.addNode();
|
614 |
614 |
Node n1 = gr.addNode();
|
615 |
615 |
Node n2 = gr.addNode();
|
616 |
616 |
|
617 |
617 |
map.set(n0, 'A');
|
618 |
618 |
map.set(n1, 'B');
|
619 |
619 |
map.set(n2, 'C');
|
620 |
620 |
map.set(n2, 'A');
|
621 |
621 |
map.set(n0, 'C');
|
622 |
622 |
|
623 |
623 |
check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A',
|
624 |
624 |
"Wrong CrossRefMap");
|
625 |
625 |
check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
|
626 |
626 |
check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
|
627 |
627 |
check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
|
628 |
628 |
|
629 |
629 |
ValueIt it = map.beginValue();
|
630 |
630 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' &&
|
631 |
631 |
it == map.endValue(), "Wrong value iterator");
|
632 |
632 |
}
|
633 |
633 |
|
634 |
634 |
// Iterable bool map
|
635 |
635 |
{
|
636 |
636 |
typedef SmartGraph Graph;
|
637 |
637 |
typedef SmartGraph::Node Item;
|
638 |
638 |
|
639 |
639 |
typedef IterableBoolMap<SmartGraph, SmartGraph::Node> Ibm;
|
640 |
640 |
checkConcept<ReferenceMap<Item, bool, bool&, const bool&>, Ibm>();
|
641 |
641 |
|
642 |
642 |
const int num = 10;
|
643 |
643 |
Graph g;
|
|
644 |
Ibm map0(g, true);
|
644 |
645 |
std::vector<Item> items;
|
645 |
646 |
for (int i = 0; i < num; ++i) {
|
646 |
647 |
items.push_back(g.addNode());
|
647 |
648 |
}
|
648 |
649 |
|
649 |
650 |
Ibm map1(g, true);
|
650 |
651 |
int n = 0;
|
651 |
652 |
for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
|
652 |
653 |
check(map1[static_cast<Item>(it)], "Wrong TrueIt");
|
653 |
654 |
++n;
|
654 |
655 |
}
|
655 |
656 |
check(n == num, "Wrong number");
|
656 |
657 |
|
657 |
658 |
n = 0;
|
658 |
659 |
for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
|
659 |
660 |
check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
|
660 |
661 |
++n;
|
661 |
662 |
}
|
662 |
663 |
check(n == num, "Wrong number");
|
663 |
664 |
check(Ibm::FalseIt(map1) == INVALID, "Wrong FalseIt");
|
664 |
665 |
check(Ibm::ItemIt(map1, false) == INVALID, "Wrong ItemIt for false");
|
665 |
666 |
|
666 |
667 |
map1[items[5]] = true;
|
667 |
668 |
|
668 |
669 |
n = 0;
|
669 |
670 |
for (Ibm::ItemIt it(map1, true); it != INVALID; ++it) {
|
670 |
671 |
check(map1[static_cast<Item>(it)], "Wrong ItemIt for true");
|
671 |
672 |
++n;
|
672 |
673 |
}
|
673 |
674 |
check(n == num, "Wrong number");
|
674 |
675 |
|
675 |
676 |
map1[items[num / 2]] = false;
|
676 |
677 |
check(map1[items[num / 2]] == false, "Wrong map value");
|
677 |
678 |
|
678 |
679 |
n = 0;
|
679 |
680 |
for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
|
680 |
681 |
check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
|
681 |
682 |
++n;
|
682 |
683 |
}
|
683 |
684 |
check(n == num - 1, "Wrong number");
|
684 |
685 |
|
685 |
686 |
n = 0;
|
686 |
687 |
for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
|
687 |
688 |
check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
|
688 |
689 |
++n;
|
689 |
690 |
}
|
690 |
691 |
check(n == 1, "Wrong number");
|
691 |
692 |
|
692 |
693 |
map1[items[0]] = false;
|
693 |
694 |
check(map1[items[0]] == false, "Wrong map value");
|
694 |
695 |
|
695 |
696 |
map1[items[num - 1]] = false;
|
696 |
697 |
check(map1[items[num - 1]] == false, "Wrong map value");
|
697 |
698 |
|
698 |
699 |
n = 0;
|
699 |
700 |
for (Ibm::TrueIt it(map1); it != INVALID; ++it) {
|
700 |
701 |
check(map1[static_cast<Item>(it)], "Wrong TrueIt for true");
|
701 |
702 |
++n;
|
702 |
703 |
}
|
703 |
704 |
check(n == num - 3, "Wrong number");
|
704 |
705 |
check(map1.trueNum() == num - 3, "Wrong number");
|
705 |
706 |
|
706 |
707 |
n = 0;
|
707 |
708 |
for (Ibm::FalseIt it(map1); it != INVALID; ++it) {
|
708 |
709 |
check(!map1[static_cast<Item>(it)], "Wrong FalseIt for true");
|
709 |
710 |
++n;
|
710 |
711 |
}
|
711 |
712 |
check(n == 3, "Wrong number");
|
712 |
713 |
check(map1.falseNum() == 3, "Wrong number");
|
713 |
714 |
}
|
714 |
715 |
|
715 |
716 |
// Iterable int map
|
716 |
717 |
{
|
717 |
718 |
typedef SmartGraph Graph;
|
718 |
719 |
typedef SmartGraph::Node Item;
|
719 |
720 |
typedef IterableIntMap<SmartGraph, SmartGraph::Node> Iim;
|
720 |
721 |
|
721 |
722 |
checkConcept<ReferenceMap<Item, int, int&, const int&>, Iim>();
|
722 |
723 |
|
723 |
724 |
const int num = 10;
|
724 |
725 |
Graph g;
|
|
726 |
Iim map0(g, 0);
|
725 |
727 |
std::vector<Item> items;
|
726 |
728 |
for (int i = 0; i < num; ++i) {
|
727 |
729 |
items.push_back(g.addNode());
|
728 |
730 |
}
|
729 |
731 |
|
730 |
732 |
Iim map1(g);
|
731 |
733 |
check(map1.size() == 0, "Wrong size");
|
732 |
734 |
|
733 |
735 |
for (int i = 0; i < num; ++i) {
|
734 |
736 |
map1[items[i]] = i;
|
735 |
737 |
}
|
736 |
738 |
check(map1.size() == num, "Wrong size");
|
737 |
739 |
|
738 |
740 |
for (int i = 0; i < num; ++i) {
|
739 |
741 |
Iim::ItemIt it(map1, i);
|
740 |
742 |
check(static_cast<Item>(it) == items[i], "Wrong value");
|
741 |
743 |
++it;
|
742 |
744 |
check(static_cast<Item>(it) == INVALID, "Wrong value");
|
743 |
745 |
}
|
744 |
746 |
|
745 |
747 |
for (int i = 0; i < num; ++i) {
|
746 |
748 |
map1[items[i]] = i % 2;
|
747 |
749 |
}
|
748 |
750 |
check(map1.size() == 2, "Wrong size");
|
749 |
751 |
|
750 |
752 |
int n = 0;
|
751 |
753 |
for (Iim::ItemIt it(map1, 0); it != INVALID; ++it) {
|
752 |
754 |
check(map1[static_cast<Item>(it)] == 0, "Wrong value");
|
753 |
755 |
++n;
|
754 |
756 |
}
|
755 |
757 |
check(n == (num + 1) / 2, "Wrong number");
|
756 |
758 |
|
757 |
759 |
for (Iim::ItemIt it(map1, 1); it != INVALID; ++it) {
|
758 |
760 |
check(map1[static_cast<Item>(it)] == 1, "Wrong value");
|
759 |
761 |
++n;
|
760 |
762 |
}
|
761 |
763 |
check(n == num, "Wrong number");
|
762 |
764 |
|
763 |
765 |
}
|
764 |
766 |
|
765 |
767 |
// Iterable value map
|
766 |
768 |
{
|
767 |
769 |
typedef SmartGraph Graph;
|
768 |
770 |
typedef SmartGraph::Node Item;
|
769 |
771 |
typedef IterableValueMap<SmartGraph, SmartGraph::Node, double> Ivm;
|
770 |
772 |
|
771 |
773 |
checkConcept<ReadWriteMap<Item, double>, Ivm>();
|
772 |
774 |
|
773 |
775 |
const int num = 10;
|
774 |
776 |
Graph g;
|
|
777 |
Ivm map0(g, 0.0);
|
775 |
778 |
std::vector<Item> items;
|
776 |
779 |
for (int i = 0; i < num; ++i) {
|
777 |
780 |
items.push_back(g.addNode());
|
778 |
781 |
}
|
779 |
782 |
|
780 |
783 |
Ivm map1(g, 0.0);
|
781 |
784 |
check(distance(map1.beginValue(), map1.endValue()) == 1, "Wrong size");
|
782 |
785 |
check(*map1.beginValue() == 0.0, "Wrong value");
|
783 |
786 |
|
784 |
787 |
for (int i = 0; i < num; ++i) {
|
785 |
788 |
map1.set(items[i], static_cast<double>(i));
|
786 |
789 |
}
|
787 |
790 |
check(distance(map1.beginValue(), map1.endValue()) == num, "Wrong size");
|
788 |
791 |
|
789 |
792 |
for (int i = 0; i < num; ++i) {
|
790 |
793 |
Ivm::ItemIt it(map1, static_cast<double>(i));
|
791 |
794 |
check(static_cast<Item>(it) == items[i], "Wrong value");
|
792 |
795 |
++it;
|
793 |
796 |
check(static_cast<Item>(it) == INVALID, "Wrong value");
|
794 |
797 |
}
|
795 |
798 |
|
796 |
799 |
for (Ivm::ValueIt vit = map1.beginValue();
|
797 |
800 |
vit != map1.endValue(); ++vit) {
|
798 |
801 |
check(map1[static_cast<Item>(Ivm::ItemIt(map1, *vit))] == *vit,
|
799 |
802 |
"Wrong ValueIt");
|
800 |
803 |
}
|
801 |
804 |
|
802 |
805 |
for (int i = 0; i < num; ++i) {
|
803 |
806 |
map1.set(items[i], static_cast<double>(i % 2));
|
804 |
807 |
}
|
805 |
808 |
check(distance(map1.beginValue(), map1.endValue()) == 2, "Wrong size");
|
806 |
809 |
|
807 |
810 |
int n = 0;
|
808 |
811 |
for (Ivm::ItemIt it(map1, 0.0); it != INVALID; ++it) {
|
809 |
812 |
check(map1[static_cast<Item>(it)] == 0.0, "Wrong value");
|
810 |
813 |
++n;
|
811 |
814 |
}
|
812 |
815 |
check(n == (num + 1) / 2, "Wrong number");
|
813 |
816 |
|
814 |
817 |
for (Ivm::ItemIt it(map1, 1.0); it != INVALID; ++it) {
|
815 |
818 |
check(map1[static_cast<Item>(it)] == 1.0, "Wrong value");
|
816 |
819 |
++n;
|
817 |
820 |
}
|
818 |
821 |
check(n == num, "Wrong number");
|
819 |
822 |
|
820 |
823 |
}
|
821 |
824 |
|
822 |
825 |
// Graph map utilities:
|
823 |
826 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue()
|
824 |
827 |
// mapFind(), mapFindIf(), mapCount(), mapCountIf()
|
825 |
828 |
// mapCopy(), mapCompare(), mapFill()
|
826 |
829 |
{
|
827 |
830 |
DIGRAPH_TYPEDEFS(SmartDigraph);
|
828 |
831 |
|
829 |
832 |
SmartDigraph g;
|
830 |
833 |
Node n1 = g.addNode();
|
831 |
834 |
Node n2 = g.addNode();
|
832 |
835 |
Node n3 = g.addNode();
|
833 |
836 |
|
834 |
837 |
SmartDigraph::NodeMap<int> map1(g);
|
835 |
838 |
SmartDigraph::ArcMap<char> map2(g);
|
836 |
839 |
ConstMap<Node, A> cmap1 = A();
|
837 |
840 |
ConstMap<Arc, C> cmap2 = C(0);
|
838 |
841 |
|
839 |
842 |
map1[n1] = 10;
|
840 |
843 |
map1[n2] = 5;
|
841 |
844 |
map1[n3] = 12;
|
842 |
845 |
|
843 |
846 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue()
|
844 |
847 |
check(mapMin(g, map1) == n2, "Wrong mapMin()");
|
845 |
848 |
check(mapMax(g, map1) == n3, "Wrong mapMax()");
|
846 |
849 |
check(mapMin(g, map1, std::greater<int>()) == n3, "Wrong mapMin()");
|
847 |
850 |
check(mapMax(g, map1, std::greater<int>()) == n2, "Wrong mapMax()");
|
848 |
851 |
check(mapMinValue(g, map1) == 5, "Wrong mapMinValue()");
|
849 |
852 |
check(mapMaxValue(g, map1) == 12, "Wrong mapMaxValue()");
|
850 |
853 |
|
851 |
854 |
check(mapMin(g, map2) == INVALID, "Wrong mapMin()");
|
852 |
855 |
check(mapMax(g, map2) == INVALID, "Wrong mapMax()");
|
853 |
856 |
|
854 |
857 |
check(mapMin(g, cmap1) != INVALID, "Wrong mapMin()");
|
855 |
858 |
check(mapMax(g, cmap2) == INVALID, "Wrong mapMax()");
|
856 |
859 |
|
857 |
860 |
Arc a1 = g.addArc(n1, n2);
|
858 |
861 |
Arc a2 = g.addArc(n1, n3);
|
859 |
862 |
Arc a3 = g.addArc(n2, n3);
|
860 |
863 |
Arc a4 = g.addArc(n3, n1);
|
861 |
864 |
|
862 |
865 |
map2[a1] = 'b';
|
863 |
866 |
map2[a2] = 'a';
|
864 |
867 |
map2[a3] = 'b';
|
865 |
868 |
map2[a4] = 'c';
|
866 |
869 |
|
867 |
870 |
// mapMin(), mapMax(), mapMinValue(), mapMaxValue()
|
868 |
871 |
check(mapMin(g, map2) == a2, "Wrong mapMin()");
|
869 |
872 |
check(mapMax(g, map2) == a4, "Wrong mapMax()");
|
870 |
873 |
check(mapMin(g, map2, std::greater<int>()) == a4, "Wrong mapMin()");
|