deba@2231: /* -*- C++ -*- deba@2231: * deba@2231: * This file is a part of LEMON, a generic C++ optimization library deba@2231: * deba@2231: * Copyright (C) 2003-2006 deba@2231: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport deba@2231: * (Egervary Research Group on Combinatorial Optimization, EGRES). deba@2231: * deba@2231: * Permission to use, modify and distribute this software is granted deba@2231: * provided that this copyright notice appears in all copies. For deba@2231: * precise terms see the accompanying LICENSE file. deba@2231: * deba@2231: * This software is provided "AS IS" with no warranty of any kind, deba@2231: * express or implied, and with no claim as to its suitability for any deba@2231: * purpose. deba@2231: * deba@2231: */ deba@2231: deba@2231: #include deba@2231: #include deba@2231: #include deba@2231: #include deba@2231: #include deba@2231: deba@2231: #include deba@2231: deba@2231: #include "test_tools.h" deba@2231: deba@2231: deba@2231: using namespace lemon; deba@2231: using namespace lemon::concept; deba@2231: deba@2231: void check_concepts() { deba@2231: deba@2231: { // checking graph components deba@2231: checkConcept(); deba@2231: deba@2231: checkConcept, deba@2231: IDableBpUGraphComponent<> >(); deba@2231: deba@2231: checkConcept, deba@2231: IterableBpUGraphComponent<> >(); deba@2231: deba@2231: checkConcept, deba@2231: MappableBpUGraphComponent<> >(); deba@2231: deba@2231: } deba@2231: { deba@2231: checkConcept(); deba@2231: deba@2231: checkConcept(); deba@2231: deba@2231: checkConcept(); deba@2231: deba@2231: checkConcept(); deba@2231: deba@2231: } deba@2231: } deba@2231: deba@2231: template deba@2231: void check_item_counts(Graph &g, int an, int bn, int e) { deba@2231: int nn = 0; deba@2231: for (typename Graph::NodeIt it(g); it != INVALID; ++it) { deba@2231: ++nn; deba@2231: } deba@2231: deba@2231: check(nn == an + bn, "Wrong node number."); deba@2231: check(countNodes(g) == an + bn, "Wrong node number."); deba@2231: deba@2231: int ann = 0; deba@2231: for (typename Graph::ANodeIt it(g); it != INVALID; ++it) { deba@2231: ++ann; deba@2231: } deba@2231: deba@2231: check(ann == an, "Wrong node number."); deba@2231: check(countANodes(g) == an, "Wrong node number."); deba@2231: deba@2231: int bnn = 0; deba@2231: for (typename Graph::BNodeIt it(g); it != INVALID; ++it) { deba@2231: ++bnn; deba@2231: } deba@2231: deba@2231: check(bnn == bn, "Wrong node number."); deba@2231: check(countBNodes(g) == bn, "Wrong node number."); deba@2231: deba@2231: int ee = 0; deba@2231: for (typename Graph::EdgeIt it(g); it != INVALID; ++it) { deba@2231: ++ee; deba@2231: } deba@2231: deba@2231: check(ee == 2*e, "Wrong edge number."); deba@2231: check(countEdges(g) == 2*e, "Wrong edge number."); deba@2231: deba@2231: int uee = 0; deba@2231: for (typename Graph::UEdgeIt it(g); it != INVALID; ++it) { deba@2231: ++uee; deba@2231: } deba@2231: deba@2231: check(uee == e, "Wrong uedge number."); deba@2231: check(countUEdges(g) == e, "Wrong uedge number."); deba@2231: } deba@2231: deba@2231: template deba@2231: void check_graph() { deba@2231: deba@2231: typedef typename Graph::Node Node; deba@2231: typedef typename Graph::UEdge UEdge; deba@2231: typedef typename Graph::Edge Edge; deba@2231: typedef typename Graph::NodeIt NodeIt; deba@2231: typedef typename Graph::UEdgeIt UEdgeIt; deba@2231: typedef typename Graph::EdgeIt EdgeIt; deba@2231: deba@2231: Graph g; deba@2231: deba@2231: check_item_counts(g, 0, 0, 0); deba@2231: deba@2231: Node deba@2231: an1 = g.addANode(), deba@2231: an2 = g.addANode(), deba@2231: an3 = g.addANode(), deba@2231: bn1 = g.addBNode(), deba@2231: bn2 = g.addBNode(); deba@2231: deba@2231: UEdge deba@2231: e1 = g.addEdge(an1, bn1), deba@2231: e2 = g.addEdge(an2, bn1), deba@2231: e3 = g.addEdge(an3, bn2); deba@2231: deba@2231: check_item_counts(g, 3, 2, 3); deba@2231: } deba@2231: deba@2231: int main() { deba@2231: check_concepts(); deba@2231: deba@2231: check_graph(); deba@2231: check_graph(); deba@2231: deba@2231: { deba@2231: FullBpUGraph g(5, 10); deba@2231: check_item_counts(g, 5, 10, 50); deba@2231: } deba@2231: deba@2231: std::cout << __FILE__ ": All tests passed.\n"; deba@2231: deba@2231: return 0; deba@2231: }