test/matrix_maps_test.cc
changeset 2039 dacc4ce9474d
parent 1956 a055123339d5
child 2242 16523135943d
     1.1 --- a/test/matrix_maps_test.cc	Tue Apr 04 17:45:35 2006 +0000
     1.2 +++ b/test/matrix_maps_test.cc	Thu Apr 06 09:33:29 2006 +0000
     1.3 @@ -40,6 +40,7 @@
     1.4  int main() {
     1.5    typedef SmartGraph Graph;
     1.6    typedef Graph::Node Node;
     1.7 +  typedef Graph::Edge Edge;
     1.8  
     1.9    { // checking MatrixMap for int
    1.10      typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
    1.11 @@ -124,6 +125,95 @@
    1.12      }
    1.13    }
    1.14  
    1.15 +  { // checking MatrixMap for int
    1.16 +    typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, int> IntMatrixMap;
    1.17 +    checkConcept<ReferenceMatrixMap<Node, Edge, int, 
    1.18 +      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
    1.19 +      IntMatrixMap>();
    1.20 +
    1.21 +  }
    1.22 +
    1.23 +  { // checking MatrixMap for bool
    1.24 +    typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, bool> BoolMatrixMap;
    1.25 +    checkConcept<ReferenceMatrixMap<Node, Edge, bool, 
    1.26 +      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
    1.27 +      BoolMatrixMap>();
    1.28 +
    1.29 +  }
    1.30 +
    1.31 +  {
    1.32 +    Graph graph1, graph2;
    1.33 +    typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, int> IntMatrixMap;
    1.34 +    IntMatrixMap matrix(graph1, graph2);
    1.35 +    for (int i = 0; i < 10; ++i) {
    1.36 +      graph1.addNode();
    1.37 +    }
    1.38 +    graph2.addNode();
    1.39 +    for (int i = 0; i < 20; ++i) {
    1.40 +      graph2.addEdge(Graph::NodeIt(graph2), Graph::NodeIt(graph2));
    1.41 +    }
    1.42 +    for (Graph::NodeIt it(graph1); it != INVALID; ++it) {
    1.43 +      for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) {
    1.44 +	int val = urandom(100);
    1.45 +	matrix.set(it, jt, val);
    1.46 +	check(matrix(it, jt) == val, "Wrong assign");
    1.47 +	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
    1.48 +	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
    1.49 +      }
    1.50 +    }
    1.51 +    const IntMatrixMap& cm = matrix;
    1.52 +    for (Graph::NodeIt it(graph1); it != INVALID; ++it) {
    1.53 +      for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) {
    1.54 +	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
    1.55 +	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
    1.56 +      }
    1.57 +    }
    1.58 +  }
    1.59 +
    1.60 +  { // checking MatrixMap for int
    1.61 +    typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, int> IntMatrixMap;
    1.62 +    checkConcept<ReferenceMatrixMap<Node, Node, int, 
    1.63 +      IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
    1.64 +      IntMatrixMap>();
    1.65 +
    1.66 +  }
    1.67 +
    1.68 +  { // checking MatrixMap for bool
    1.69 +    typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, bool> BoolMatrixMap;
    1.70 +    checkConcept<ReferenceMatrixMap<Node, Node, bool, 
    1.71 +      BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
    1.72 +      BoolMatrixMap>();
    1.73 +
    1.74 +  }
    1.75 +
    1.76 +  {
    1.77 +    Graph graph;
    1.78 +    typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, int> IntMatrixMap;
    1.79 +    IntMatrixMap matrix(graph, graph);
    1.80 +    for (int i = 0; i < 10; ++i) {
    1.81 +      graph.addNode();
    1.82 +    }
    1.83 +    for (int i = 0; i < 20; ++i) {
    1.84 +      graph.addEdge(Graph::NodeIt(graph), Graph::NodeIt(graph));
    1.85 +    }
    1.86 +    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    1.87 +      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    1.88 +	int val = urandom(100);
    1.89 +	matrix.set(it, jt, val);
    1.90 +	check(matrix(it, jt) == val, "Wrong assign");
    1.91 +	check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
    1.92 +	check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
    1.93 +      }
    1.94 +    }
    1.95 +    const IntMatrixMap& cm = matrix;
    1.96 +    for (Graph::NodeIt it(graph); it != INVALID; ++it) {
    1.97 +      for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
    1.98 +	check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
    1.99 +	check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
   1.100 +      }
   1.101 +    }
   1.102 +  }
   1.103 +
   1.104    std::cout << __FILE__ ": All tests passed.\n";
   1.105  
   1.106    return 0;