| [1728] | 1 | // -*- c++ -*- | 
|---|
|  | 2 |  | 
|---|
|  | 3 | #include <iostream> | 
|---|
|  | 4 | #include <vector> | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #include <lemon/concept_check.h> | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include <lemon/concept/matrix_maps.h> | 
|---|
|  | 9 | #include <lemon/concept/maps.h> | 
|---|
|  | 10 | #include <lemon/concept/graph.h> | 
|---|
|  | 11 |  | 
|---|
|  | 12 | #include <lemon/matrix_maps.h> | 
|---|
|  | 13 |  | 
|---|
|  | 14 | #include <lemon/smart_graph.h> | 
|---|
|  | 15 |  | 
|---|
|  | 16 | #include "test_tools.h" | 
|---|
|  | 17 | #include "graph_test.h" | 
|---|
|  | 18 | #include "map_test.h" | 
|---|
|  | 19 |  | 
|---|
|  | 20 |  | 
|---|
|  | 21 | using namespace lemon; | 
|---|
|  | 22 | using namespace lemon::concept; | 
|---|
|  | 23 |  | 
|---|
|  | 24 | int main() { | 
|---|
|  | 25 | typedef SmartGraph Graph; | 
|---|
|  | 26 | typedef Graph::Node Node; | 
|---|
|  | 27 |  | 
|---|
|  | 28 | { // checking MatrixMap for int | 
|---|
|  | 29 | typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap; | 
|---|
|  | 30 | checkConcept<ReferenceMatrixMap<Node, Node, int, | 
|---|
|  | 31 | IntMatrixMap::Reference, IntMatrixMap::ConstReference>, | 
|---|
|  | 32 | IntMatrixMap>(); | 
|---|
|  | 33 |  | 
|---|
|  | 34 | } | 
|---|
|  | 35 |  | 
|---|
|  | 36 | { // checking MatrixMap for bool | 
|---|
|  | 37 | typedef DynamicMatrixMap<Graph, Node, bool> BoolMatrixMap; | 
|---|
|  | 38 | checkConcept<ReferenceMatrixMap<Node, Node, bool, | 
|---|
|  | 39 | BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>, | 
|---|
|  | 40 | BoolMatrixMap>(); | 
|---|
|  | 41 |  | 
|---|
|  | 42 | } | 
|---|
|  | 43 |  | 
|---|
|  | 44 | { | 
|---|
|  | 45 | Graph graph; | 
|---|
|  | 46 | typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap; | 
|---|
|  | 47 | IntMatrixMap matrix(graph); | 
|---|
|  | 48 | for (int i = 0; i < 10; ++i) { | 
|---|
|  | 49 | graph.addNode(); | 
|---|
|  | 50 | } | 
|---|
|  | 51 | for (Graph::NodeIt it(graph); it != INVALID; ++it) { | 
|---|
|  | 52 | for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { | 
|---|
|  | 53 | int val = urandom(100); | 
|---|
|  | 54 | matrix.set(it, jt, val); | 
|---|
|  | 55 | check(matrix(it, jt) == val, "Wrong assign"); | 
|---|
|  | 56 | check(matrix(it, jt) == matrixColMap(matrix, it)[jt], "Wrong colMap"); | 
|---|
|  | 57 | check(matrix(it, jt) == matrixRowMap(matrix, jt)[it], "Wrong rowMap"); | 
|---|
|  | 58 | } | 
|---|
|  | 59 | } | 
|---|
|  | 60 | const IntMatrixMap& cm = matrix; | 
|---|
|  | 61 | for (Graph::NodeIt it(graph); it != INVALID; ++it) { | 
|---|
|  | 62 | for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { | 
|---|
|  | 63 | check(cm(it, jt) == matrixColMap(cm, it)[jt], "Wrong colMap"); | 
|---|
|  | 64 | check(cm(it, jt) == matrixRowMap(cm, jt)[it], "Wrong rowMap"); | 
|---|
|  | 65 | } | 
|---|
|  | 66 | } | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | { // checking MatrixMap for int | 
|---|
|  | 70 | typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap; | 
|---|
|  | 71 | checkConcept<ReferenceMatrixMap<Node, Node, int, | 
|---|
|  | 72 | IntMatrixMap::Reference, IntMatrixMap::ConstReference>, | 
|---|
|  | 73 | IntMatrixMap>(); | 
|---|
|  | 74 |  | 
|---|
|  | 75 | } | 
|---|
|  | 76 |  | 
|---|
|  | 77 | { // checking MatrixMap for bool | 
|---|
|  | 78 | typedef DynamicSymMatrixMap<Graph, Node, bool> BoolMatrixMap; | 
|---|
|  | 79 | checkConcept<ReferenceMatrixMap<Node, Node, bool, | 
|---|
|  | 80 | BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>, | 
|---|
|  | 81 | BoolMatrixMap>(); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | } | 
|---|
|  | 84 |  | 
|---|
|  | 85 | { | 
|---|
|  | 86 | Graph graph; | 
|---|
|  | 87 | typedef DynamicSymMatrixMap<Graph, Node, int> IntMatrixMap; | 
|---|
|  | 88 | IntMatrixMap matrix(graph); | 
|---|
|  | 89 | for (int i = 0; i < 10; ++i) { | 
|---|
|  | 90 | graph.addNode(); | 
|---|
|  | 91 | } | 
|---|
|  | 92 | for (Graph::NodeIt it(graph); it != INVALID; ++it) { | 
|---|
|  | 93 | for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { | 
|---|
|  | 94 | int val = urandom(100); | 
|---|
|  | 95 | matrix.set(it, jt, val); | 
|---|
|  | 96 | check(matrix(it, jt) == val, "Wrong assign"); | 
|---|
|  | 97 | check(matrix(jt, it) == val, "Wrong assign"); | 
|---|
|  | 98 | check(matrix(it, jt) == matrixColMap(matrix, it)[jt], "Wrong colMap"); | 
|---|
|  | 99 | check(matrix(it, jt) == matrixRowMap(matrix, jt)[it], "Wrong rowMap"); | 
|---|
|  | 100 | } | 
|---|
|  | 101 | } | 
|---|
|  | 102 | const IntMatrixMap& cm = matrix; | 
|---|
|  | 103 | for (Graph::NodeIt it(graph); it != INVALID; ++it) { | 
|---|
|  | 104 | for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { | 
|---|
|  | 105 | check(cm(it, jt) == matrixColMap(cm, it)[jt], "Wrong colMap"); | 
|---|
|  | 106 | check(cm(it, jt) == matrixRowMap(cm, jt)[it], "Wrong rowMap"); | 
|---|
|  | 107 | } | 
|---|
|  | 108 | } | 
|---|
|  | 109 | } | 
|---|
|  | 110 |  | 
|---|
|  | 111 | std::cout << __FILE__ ": All tests passed.\n"; | 
|---|
|  | 112 |  | 
|---|
|  | 113 | return 0; | 
|---|
|  | 114 | } | 
|---|