alpar@1956: /* -*- C++ -*- alpar@1956: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library alpar@1956: * alpar@2391: * Copyright (C) 2003-2007 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@1956: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@1956: * alpar@1956: * Permission to use, modify and distribute this software is granted alpar@1956: * provided that this copyright notice appears in all copies. For alpar@1956: * precise terms see the accompanying LICENSE file. alpar@1956: * alpar@1956: * This software is provided "AS IS" with no warranty of any kind, alpar@1956: * express or implied, and with no claim as to its suitability for any alpar@1956: * purpose. alpar@1956: * alpar@1956: */ deba@1728: deba@1728: #include deba@1728: #include deba@1728: deba@1728: #include deba@1728: alpar@2260: #include alpar@2260: #include alpar@2260: #include deba@1728: deba@1728: #include deba@1728: deba@1728: #include deba@1728: deba@1728: #include "test_tools.h" deba@1728: #include "graph_test.h" deba@1728: #include "map_test.h" deba@1728: deba@1728: deba@1728: using namespace lemon; alpar@2260: using namespace lemon::concepts; deba@1728: deba@1728: int main() { deba@1728: typedef SmartGraph Graph; deba@1728: typedef Graph::Node Node; deba@2039: typedef Graph::Edge Edge; deba@1728: deba@1728: { // checking MatrixMap for int deba@1728: typedef DynamicMatrixMap IntMatrixMap; deba@1728: checkConcept, deba@1728: IntMatrixMap>(); deba@1728: deba@1728: } deba@1728: deba@1728: { // checking MatrixMap for bool deba@1728: typedef DynamicMatrixMap BoolMatrixMap; deba@1728: checkConcept, deba@1728: BoolMatrixMap>(); deba@1728: deba@1728: } deba@1728: deba@1728: { deba@1728: Graph graph; deba@1728: typedef DynamicMatrixMap IntMatrixMap; deba@1728: IntMatrixMap matrix(graph); deba@1728: for (int i = 0; i < 10; ++i) { deba@1728: graph.addNode(); deba@1728: } deba@1728: for (Graph::NodeIt it(graph); it != INVALID; ++it) { deba@1728: for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { deba@2242: int val = rnd[100]; deba@1728: matrix.set(it, jt, val); deba@1728: check(matrix(it, jt) == val, "Wrong assign"); deba@1751: check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); deba@1751: check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); deba@1728: } deba@1728: } deba@1728: const IntMatrixMap& cm = matrix; deba@1728: for (Graph::NodeIt it(graph); it != INVALID; ++it) { deba@1728: for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { deba@1751: check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); deba@1751: check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); deba@1728: } deba@1728: } deba@1728: } deba@1728: deba@1728: { // checking MatrixMap for int deba@1728: typedef DynamicSymMatrixMap IntMatrixMap; deba@1728: checkConcept, deba@1728: IntMatrixMap>(); deba@1728: deba@1728: } deba@1728: deba@1728: { // checking MatrixMap for bool deba@1728: typedef DynamicSymMatrixMap BoolMatrixMap; deba@1728: checkConcept, deba@1728: BoolMatrixMap>(); deba@1728: deba@1728: } deba@1728: deba@1728: { deba@1728: Graph graph; deba@1728: typedef DynamicSymMatrixMap IntMatrixMap; deba@1728: IntMatrixMap matrix(graph); deba@1728: for (int i = 0; i < 10; ++i) { deba@1728: graph.addNode(); deba@1728: } deba@1728: for (Graph::NodeIt it(graph); it != INVALID; ++it) { deba@1728: for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { deba@2242: int val = rnd[100]; deba@1728: matrix.set(it, jt, val); deba@1728: check(matrix(it, jt) == val, "Wrong assign"); deba@1728: check(matrix(jt, it) == val, "Wrong assign"); deba@1751: check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); deba@1751: check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); deba@1728: } deba@1728: } deba@1728: const IntMatrixMap& cm = matrix; deba@1728: for (Graph::NodeIt it(graph); it != INVALID; ++it) { deba@1728: for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { deba@1751: check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); deba@1751: check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); deba@1728: } deba@1728: } deba@1728: } deba@1728: deba@2039: { // checking MatrixMap for int deba@2039: typedef DynamicAsymMatrixMap IntMatrixMap; deba@2039: checkConcept, deba@2039: IntMatrixMap>(); deba@2039: deba@2039: } deba@2039: deba@2039: { // checking MatrixMap for bool deba@2039: typedef DynamicAsymMatrixMap BoolMatrixMap; deba@2039: checkConcept, deba@2039: BoolMatrixMap>(); deba@2039: deba@2039: } deba@2039: deba@2039: { deba@2039: Graph graph1, graph2; deba@2039: typedef DynamicAsymMatrixMap IntMatrixMap; deba@2039: IntMatrixMap matrix(graph1, graph2); deba@2039: for (int i = 0; i < 10; ++i) { deba@2039: graph1.addNode(); deba@2039: } deba@2039: graph2.addNode(); deba@2039: for (int i = 0; i < 20; ++i) { deba@2039: graph2.addEdge(Graph::NodeIt(graph2), Graph::NodeIt(graph2)); deba@2039: } deba@2039: for (Graph::NodeIt it(graph1); it != INVALID; ++it) { deba@2039: for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) { deba@2242: int val = rnd[100]; deba@2039: matrix.set(it, jt, val); deba@2039: check(matrix(it, jt) == val, "Wrong assign"); deba@2039: check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); deba@2039: check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); deba@2039: } deba@2039: } deba@2039: const IntMatrixMap& cm = matrix; deba@2039: for (Graph::NodeIt it(graph1); it != INVALID; ++it) { deba@2039: for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) { deba@2039: check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); deba@2039: check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); deba@2039: } deba@2039: } deba@2039: } deba@2039: deba@2039: { // checking MatrixMap for int deba@2039: typedef DynamicAsymMatrixMap IntMatrixMap; deba@2039: checkConcept, deba@2039: IntMatrixMap>(); deba@2039: deba@2039: } deba@2039: deba@2039: { // checking MatrixMap for bool deba@2039: typedef DynamicAsymMatrixMap BoolMatrixMap; deba@2039: checkConcept, deba@2039: BoolMatrixMap>(); deba@2039: deba@2039: } deba@2039: deba@2039: { deba@2039: Graph graph; deba@2039: typedef DynamicAsymMatrixMap IntMatrixMap; deba@2039: IntMatrixMap matrix(graph, graph); deba@2039: for (int i = 0; i < 10; ++i) { deba@2039: graph.addNode(); deba@2039: } deba@2039: for (int i = 0; i < 20; ++i) { deba@2039: graph.addEdge(Graph::NodeIt(graph), Graph::NodeIt(graph)); deba@2039: } deba@2039: for (Graph::NodeIt it(graph); it != INVALID; ++it) { deba@2039: for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { deba@2242: int val = rnd[100]; deba@2039: matrix.set(it, jt, val); deba@2039: check(matrix(it, jt) == val, "Wrong assign"); deba@2039: check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap"); deba@2039: check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap"); deba@2039: } deba@2039: } deba@2039: const IntMatrixMap& cm = matrix; deba@2039: for (Graph::NodeIt it(graph); it != INVALID; ++it) { deba@2039: for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) { deba@2039: check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap"); deba@2039: check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap"); deba@2039: } deba@2039: } deba@2039: } deba@2039: deba@1728: std::cout << __FILE__ ": All tests passed.\n"; deba@1728: deba@1728: return 0; deba@1728: }