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