[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"); |
---|
[1751] | 56 | check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); |
---|
| 57 | check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); |
---|
[1728] | 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) { |
---|
[1751] | 63 | check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); |
---|
| 64 | check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); |
---|
[1728] | 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"); |
---|
[1751] | 98 | check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); |
---|
| 99 | check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); |
---|
[1728] | 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) { |
---|
[1751] | 105 | check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); |
---|
| 106 | check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); |
---|
[1728] | 107 | } |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | std::cout << __FILE__ ": All tests passed.\n"; |
---|
| 112 | |
---|
| 113 | return 0; |
---|
| 114 | } |
---|