[946] | 1 | /* -*- C++ -*- |
---|
[1435] | 2 | * test/graph_utils_test.h - Part of LEMON, a generic C++ optimization library |
---|
[946] | 3 | * |
---|
[1164] | 4 | * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
[1359] | 5 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
[946] | 6 | * |
---|
| 7 | * Permission to use, modify and distribute this software is granted |
---|
| 8 | * provided that this copyright notice appears in all copies. For |
---|
| 9 | * precise terms see the accompanying LICENSE file. |
---|
| 10 | * |
---|
| 11 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 12 | * express or implied, and with no claim as to its suitability for any |
---|
| 13 | * purpose. |
---|
| 14 | * |
---|
| 15 | */ |
---|
| 16 | #ifndef LEMON_TEST_GRAPH_UTILS_TEST_H |
---|
| 17 | #define LEMON_TEST_GRAPH_UTILS_TEST_H |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #include "test_tools.h" |
---|
[1568] | 21 | #include <cstdlib> |
---|
| 22 | #include <ctime> |
---|
[946] | 23 | |
---|
| 24 | //! \ingroup misc |
---|
| 25 | //! \file |
---|
| 26 | //! \brief Test cases for graph utils. |
---|
| 27 | namespace lemon { |
---|
| 28 | |
---|
| 29 | template <typename Graph> |
---|
| 30 | void checkGraphCounters() { |
---|
| 31 | const int num = 5; |
---|
| 32 | Graph graph; |
---|
| 33 | addPetersen(graph, num); |
---|
| 34 | bidirGraph(graph); |
---|
[977] | 35 | check(countNodes(graph) == 2*num, "Wrong node number."); |
---|
| 36 | check(countEdges(graph) == 6*num, "Wrong edge number."); |
---|
[946] | 37 | for (typename Graph::NodeIt it(graph); it != INVALID; ++it) { |
---|
[977] | 38 | check(countOutEdges(graph, it) == 3, "Wrong out degree number."); |
---|
| 39 | check(countInEdges(graph, it) == 3, "Wrong in degree number."); |
---|
[946] | 40 | } |
---|
| 41 | } |
---|
[1568] | 42 | |
---|
| 43 | template <typename Graph> |
---|
| 44 | void checkFindEdge() { |
---|
| 45 | typedef typename Graph::Node Node; |
---|
| 46 | typedef typename Graph::Edge Edge; |
---|
| 47 | typedef typename Graph::NodeIt NodeIt; |
---|
| 48 | typedef typename Graph::EdgeIt EdgeIt; |
---|
| 49 | Graph graph; |
---|
| 50 | srand(time(0)); |
---|
| 51 | for (int i = 0; i < 10; ++i) { |
---|
| 52 | graph.addNode(); |
---|
| 53 | } |
---|
| 54 | DescriptorMap<Graph, Node> nodes(graph); |
---|
| 55 | typename DescriptorMap<Graph, Node>::InverseMap invNodes(nodes); |
---|
| 56 | for (int i = 0; i < 100; ++i) { |
---|
| 57 | int src = (int)(rand() / (RAND_MAX + 1.0) * invNodes.size()); |
---|
| 58 | int trg = (int)(rand() / (RAND_MAX + 1.0) * invNodes.size()); |
---|
| 59 | graph.addEdge(invNodes[src], invNodes[trg]); |
---|
| 60 | } |
---|
| 61 | typename Graph::template EdgeMap<bool> found(graph, false); |
---|
| 62 | DescriptorMap<Graph, Edge> edges(graph); |
---|
| 63 | for (NodeIt src(graph); src != INVALID; ++src) { |
---|
| 64 | for (NodeIt trg(graph); trg != INVALID; ++trg) { |
---|
| 65 | for (ConEdgeIt<Graph> con(graph, src, trg); con != INVALID; ++con) { |
---|
| 66 | check(graph.source(con) == src, "Wrong source."); |
---|
| 67 | check(graph.target(con) == trg, "Wrong target."); |
---|
| 68 | check(found[con] == false, "The edge found already."); |
---|
| 69 | found[con] = true; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | for (EdgeIt it(graph); it != INVALID; ++it) { |
---|
| 74 | check(found[it] == true, "The edge is not found."); |
---|
| 75 | } |
---|
| 76 | } |
---|
[946] | 77 | |
---|
| 78 | } //namespace lemon |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | #endif |
---|