test/arc_look_up_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 17 Oct 2018 18:55:53 +0200
changeset 1174 7c86f14b3bc5
parent 1092 dceba191c00d
permissions -rw-r--r--
Merge #1.3 related bugfix heads
alpar@993
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@993
     2
 *
alpar@993
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@993
     4
 *
alpar@1092
     5
 * Copyright (C) 2003-2013
alpar@993
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@993
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@993
     8
 *
alpar@993
     9
 * Permission to use, modify and distribute this software is granted
alpar@993
    10
 * provided that this copyright notice appears in all copies. For
alpar@993
    11
 * precise terms see the accompanying LICENSE file.
alpar@993
    12
 *
alpar@993
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@993
    14
 * express or implied, and with no claim as to its suitability for any
alpar@993
    15
 * purpose.
alpar@993
    16
 *
alpar@993
    17
 */
alpar@993
    18
alpar@993
    19
#include <iostream>
alpar@993
    20
#include "lemon/list_graph.h"
alpar@993
    21
#include "lemon/lgf_reader.h"
alpar@993
    22
alpar@993
    23
#include "test_tools.h"
alpar@993
    24
alpar@993
    25
using namespace lemon;
alpar@993
    26
alpar@993
    27
const std::string lgf =
alpar@993
    28
  "@nodes\n"
alpar@993
    29
"label\n"
alpar@993
    30
"0\n"
alpar@993
    31
"1\n"
alpar@993
    32
"2\n"
alpar@993
    33
"3\n"
alpar@993
    34
"4\n"
alpar@993
    35
"5\n"
alpar@993
    36
"6\n"
alpar@993
    37
"@arcs\n"
alpar@993
    38
"label\n"
alpar@993
    39
"5 6 0\n"
alpar@993
    40
"5 4 1\n"
alpar@993
    41
"4 6 2\n"
alpar@993
    42
"3 4 3\n"
alpar@993
    43
"3 4 4\n"
alpar@993
    44
"3 2 5\n"
alpar@993
    45
"3 5 6\n"
alpar@993
    46
"3 5 7\n"
alpar@993
    47
"3 5 8\n"
alpar@993
    48
"3 5 9\n"
alpar@993
    49
"2 4 10\n"
alpar@993
    50
"2 4 11\n"
alpar@993
    51
"2 4 12\n"
alpar@993
    52
"2 4 13\n"
alpar@993
    53
"1 2 14\n"
alpar@993
    54
"1 2 15\n"
alpar@993
    55
"1 0 16\n"
alpar@993
    56
"1 3 17\n"
alpar@993
    57
"1 3 18\n"
alpar@993
    58
"1 3 19\n"
alpar@993
    59
"1 3 20\n"
alpar@993
    60
"0 2 21\n"
alpar@993
    61
"0 2 22\n"
alpar@993
    62
"0 2 23\n"
alpar@993
    63
"0 2 24\n";
alpar@993
    64
alpar@993
    65
alpar@993
    66
int main() {
alpar@993
    67
  ListDigraph graph;
alpar@993
    68
  std::istringstream lgfs(lgf);
alpar@993
    69
  DigraphReader<ListDigraph>(graph, lgfs).run();
alpar@1092
    70
alpar@993
    71
  AllArcLookUp<ListDigraph> lookup(graph);
alpar@1092
    72
alpar@993
    73
  int numArcs = countArcs(graph);
alpar@1092
    74
alpar@993
    75
  int arcCnt = 0;
alpar@993
    76
  for(ListDigraph::NodeIt n1(graph); n1 != INVALID; ++n1)
alpar@993
    77
    for(ListDigraph::NodeIt n2(graph); n2 != INVALID; ++n2)
alpar@993
    78
      for(ListDigraph::Arc a = lookup(n1, n2); a != INVALID;
alpar@1092
    79
          a = lookup(n1, n2, a))
alpar@1092
    80
        ++arcCnt;
alpar@993
    81
  check(arcCnt==numArcs, "Wrong total number of arcs");
alpar@993
    82
alpar@993
    83
  return 0;
alpar@993
    84
}