test/matrix_maps_test.cc
changeset 2177 416a7030b7e3
parent 1956 a055123339d5
child 2242 16523135943d
equal deleted inserted replaced
2:8fae5647618b 3:a8778e88bb60
    38 using namespace lemon::concept;
    38 using namespace lemon::concept;
    39 
    39 
    40 int main() {
    40 int main() {
    41   typedef SmartGraph Graph;
    41   typedef SmartGraph Graph;
    42   typedef Graph::Node Node;
    42   typedef Graph::Node Node;
       
    43   typedef Graph::Edge Edge;
    43 
    44 
    44   { // checking MatrixMap for int
    45   { // checking MatrixMap for int
    45     typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
    46     typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
    46     checkConcept<ReferenceMatrixMap<Node, Node, int, 
    47     checkConcept<ReferenceMatrixMap<Node, Node, int, 
    47       IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
    48       IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
   122 	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
   123 	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
   123       }
   124       }
   124     }
   125     }
   125   }
   126   }
   126 
   127 
       
   128   { // checking MatrixMap for int
       
   129     typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, int> IntMatrixMap;
       
   130     checkConcept<ReferenceMatrixMap<Node, Edge, int, 
       
   131       IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
       
   132       IntMatrixMap>();
       
   133 
       
   134   }
       
   135 
       
   136   { // checking MatrixMap for bool
       
   137     typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, bool> BoolMatrixMap;
       
   138     checkConcept<ReferenceMatrixMap<Node, Edge, bool, 
       
   139       BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
       
   140       BoolMatrixMap>();
       
   141 
       
   142   }
       
   143 
       
   144   {
       
   145     Graph graph1, graph2;
       
   146     typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, int> IntMatrixMap;
       
   147     IntMatrixMap matrix(graph1, graph2);
       
   148     for (int i = 0; i < 10; ++i) {
       
   149       graph1.addNode();
       
   150     }
       
   151     graph2.addNode();
       
   152     for (int i = 0; i < 20; ++i) {
       
   153       graph2.addEdge(Graph::NodeIt(graph2), Graph::NodeIt(graph2));
       
   154     }
       
   155     for (Graph::NodeIt it(graph1); it != INVALID; ++it) {
       
   156       for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) {
       
   157 	int val = urandom(100);
       
   158 	matrix.set(it, jt, val);
       
   159 	check(matrix(it, jt) == val, "Wrong assign");
       
   160 	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
       
   161 	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
       
   162       }
       
   163     }
       
   164     const IntMatrixMap& cm = matrix;
       
   165     for (Graph::NodeIt it(graph1); it != INVALID; ++it) {
       
   166       for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) {
       
   167 	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
       
   168 	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
       
   169       }
       
   170     }
       
   171   }
       
   172 
       
   173   { // checking MatrixMap for int
       
   174     typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, int> IntMatrixMap;
       
   175     checkConcept<ReferenceMatrixMap<Node, Node, int, 
       
   176       IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
       
   177       IntMatrixMap>();
       
   178 
       
   179   }
       
   180 
       
   181   { // checking MatrixMap for bool
       
   182     typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, bool> BoolMatrixMap;
       
   183     checkConcept<ReferenceMatrixMap<Node, Node, bool, 
       
   184       BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
       
   185       BoolMatrixMap>();
       
   186 
       
   187   }
       
   188 
       
   189   {
       
   190     Graph graph;
       
   191     typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, int> IntMatrixMap;
       
   192     IntMatrixMap matrix(graph, graph);
       
   193     for (int i = 0; i < 10; ++i) {
       
   194       graph.addNode();
       
   195     }
       
   196     for (int i = 0; i < 20; ++i) {
       
   197       graph.addEdge(Graph::NodeIt(graph), Graph::NodeIt(graph));
       
   198     }
       
   199     for (Graph::NodeIt it(graph); it != INVALID; ++it) {
       
   200       for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
       
   201 	int val = urandom(100);
       
   202 	matrix.set(it, jt, val);
       
   203 	check(matrix(it, jt) == val, "Wrong assign");
       
   204 	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
       
   205 	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
       
   206       }
       
   207     }
       
   208     const IntMatrixMap& cm = matrix;
       
   209     for (Graph::NodeIt it(graph); it != INVALID; ++it) {
       
   210       for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
       
   211 	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
       
   212 	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
       
   213       }
       
   214     }
       
   215   }
       
   216 
   127   std::cout << __FILE__ ": All tests passed.\n";
   217   std::cout << __FILE__ ": All tests passed.\n";
   128 
   218 
   129   return 0;
   219   return 0;
   130 }
   220 }