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