test/graph_utils_test.h
author Balazs Dezso <deba@inf.elte.hu>
Tue, 22 Apr 2008 15:07:04 +0200
changeset 140 356930927a71
permissions -rw-r--r--
New implementation of GRAPH_TYPEDEFS
deba@139
     1
/* -*- C++ -*-
deba@139
     2
 *
deba@139
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@139
     4
 *
deba@139
     5
 * Copyright (C) 2003-2008
deba@139
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@139
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@139
     8
 *
deba@139
     9
 * Permission to use, modify and distribute this software is granted
deba@139
    10
 * provided that this copyright notice appears in all copies. For
deba@139
    11
 * precise terms see the accompanying LICENSE file.
deba@139
    12
 *
deba@139
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@139
    14
 * express or implied, and with no claim as to its suitability for any
deba@139
    15
 * purpose.
deba@139
    16
 *
deba@139
    17
 */
deba@139
    18
deba@139
    19
#ifndef LEMON_TEST_GRAPH_UTILS_TEST_H
deba@139
    20
#define LEMON_TEST_GRAPH_UTILS_TEST_H
deba@139
    21
deba@139
    22
deba@139
    23
#include "test_tools.h"
deba@139
    24
#include <cstdlib>
deba@139
    25
#include <ctime>
deba@139
    26
deba@139
    27
//! \ingroup misc
deba@139
    28
//! \file
deba@139
    29
//! \brief Test cases for graph utils.
deba@139
    30
namespace lemon {
deba@139
    31
  
deba@139
    32
  template <typename Digraph>
deba@139
    33
  void checkDigraphCounters() {
deba@139
    34
    const int num = 5;
deba@139
    35
    Digraph digraph;
deba@139
    36
    addPetersen(digraph, num);
deba@139
    37
    bidirDigraph(digraph);
deba@139
    38
    check(countNodes(digraph) == 2*num, "Wrong node number.");
deba@139
    39
    check(countArcs(digraph) == 6*num, "Wrong arc number.");    
deba@139
    40
    for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) {
deba@139
    41
      check(countOutArcs(digraph, it) == 3, "Wrong out degree number.");
deba@139
    42
      check(countInArcs(digraph, it) == 3, "Wrong in degree number.");
deba@139
    43
    }
deba@139
    44
  }
deba@139
    45
deba@139
    46
  template <typename Digraph>
deba@139
    47
  void checkFindArc() {
deba@139
    48
    typedef typename Digraph::Node Node;
deba@139
    49
    typedef typename Digraph::Arc Arc;
deba@139
    50
    typedef typename Digraph::NodeIt NodeIt;
deba@139
    51
    typedef typename Digraph::ArcIt ArcIt;
deba@139
    52
    Digraph digraph;
deba@139
    53
    for (int i = 0; i < 10; ++i) {
deba@139
    54
      digraph.addNode();
deba@139
    55
    }
deba@139
    56
    DescriptorMap<Digraph, Node> nodes(digraph);
deba@139
    57
    typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes);
deba@139
    58
    for (int i = 0; i < 100; ++i) {
deba@139
    59
      int src = rnd[invNodes.size()];
deba@139
    60
      int trg = rnd[invNodes.size()];
deba@139
    61
      digraph.addArc(invNodes[src], invNodes[trg]);
deba@139
    62
    }
deba@139
    63
    typename Digraph::template ArcMap<bool> found(digraph, false);
deba@139
    64
    DescriptorMap<Digraph, Arc> arcs(digraph);
deba@139
    65
    for (NodeIt src(digraph); src != INVALID; ++src) {
deba@139
    66
      for (NodeIt trg(digraph); trg != INVALID; ++trg) {
deba@139
    67
	for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) {
deba@139
    68
	  check(digraph.source(con) == src, "Wrong source.");
deba@139
    69
	  check(digraph.target(con) == trg, "Wrong target.");
deba@139
    70
	  check(found[con] == false, "The arc found already.");
deba@139
    71
	  found[con] = true;
deba@139
    72
	}
deba@139
    73
      }
deba@139
    74
    }
deba@139
    75
    for (ArcIt it(digraph); it != INVALID; ++it) {
deba@139
    76
      check(found[it] == true, "The arc is not found.");
deba@139
    77
    }
deba@139
    78
  }
deba@139
    79
  
deba@139
    80
} //namespace lemon
deba@139
    81
deba@139
    82
deba@139
    83
#endif