test/lgf_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 05 Oct 2011 12:02:56 +0200
changeset 763 08cbd48f51f0
child 761 f1398882a928
child 764 b96574ff36ec
permissions -rw-r--r--
Add lemon/lemon.pc.cmake to the release tarball (#428)
alpar@756
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@756
     2
 *
alpar@756
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@756
     4
 *
alpar@756
     5
 * Copyright (C) 2003-2011
alpar@756
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@756
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@756
     8
 *
alpar@756
     9
 * Permission to use, modify and distribute this software is granted
alpar@756
    10
 * provided that this copyright notice appears in all copies. For
alpar@756
    11
 * precise terms see the accompanying LICENSE file.
alpar@756
    12
 *
alpar@756
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@756
    14
 * express or implied, and with no claim as to its suitability for any
alpar@756
    15
 * purpose.
alpar@756
    16
 *
alpar@756
    17
 */
alpar@756
    18
alpar@756
    19
#include <lemon/list_graph.h>
alpar@756
    20
#include <lemon/lgf_reader.h>
alpar@756
    21
#include "test_tools.h"
alpar@756
    22
alpar@756
    23
using namespace lemon;
alpar@756
    24
alpar@756
    25
char test_lgf[] =
alpar@756
    26
  "@nodes\n"
alpar@756
    27
  "label\n"
alpar@756
    28
  "0\n"
alpar@756
    29
  "1\n"
alpar@756
    30
  "@arcs\n"
alpar@756
    31
  "     label\n"
alpar@756
    32
  "0 1  0\n"
alpar@756
    33
  "1 0  1\n"
alpar@756
    34
  "@attributes\n"
alpar@756
    35
  "source 0\n"
alpar@756
    36
  "target 1\n";
alpar@756
    37
alpar@756
    38
char test_lgf_nomap[] =
alpar@756
    39
  "@nodes\n"
alpar@756
    40
  "label\n"
alpar@756
    41
  "0\n"
alpar@756
    42
  "1\n"
alpar@756
    43
  "@arcs\n"
alpar@756
    44
  "     -\n"
alpar@756
    45
  "0 1\n";
alpar@756
    46
alpar@756
    47
char test_lgf_bad1[] =
alpar@756
    48
  "@nodes\n"
alpar@756
    49
  "label\n"
alpar@756
    50
  "0\n"
alpar@756
    51
  "1\n"
alpar@756
    52
  "@arcs\n"
alpar@756
    53
  "     - another\n"
alpar@756
    54
  "0 1\n";
alpar@756
    55
alpar@756
    56
char test_lgf_bad2[] =
alpar@756
    57
  "@nodes\n"
alpar@756
    58
  "label\n"
alpar@756
    59
  "0\n"
alpar@756
    60
  "1\n"
alpar@756
    61
  "@arcs\n"
alpar@756
    62
  "     label -\n"
alpar@756
    63
  "0 1\n";
alpar@756
    64
alpar@756
    65
alpar@756
    66
int main() 
alpar@756
    67
{
alpar@756
    68
  {
alpar@756
    69
    ListDigraph d; 
alpar@756
    70
    ListDigraph::Node s,t;
alpar@756
    71
    ListDigraph::ArcMap<int> label(d);
alpar@756
    72
    std::istringstream input(test_lgf);
alpar@756
    73
    digraphReader(d, input).
alpar@756
    74
      node("source", s).
alpar@756
    75
      node("target", t).
alpar@756
    76
      arcMap("label", label).
alpar@756
    77
      run();
alpar@756
    78
    check(countNodes(d) == 2,"There should be 2 nodes");
alpar@756
    79
    check(countArcs(d) == 2,"There should be 2 arcs");
alpar@756
    80
  }
alpar@756
    81
  {
alpar@756
    82
    ListGraph g;
alpar@756
    83
    ListGraph::Node s,t;
alpar@756
    84
    ListGraph::EdgeMap<int> label(g);
alpar@756
    85
    std::istringstream input(test_lgf);
alpar@756
    86
    graphReader(g, input).
alpar@756
    87
      node("source", s).
alpar@756
    88
      node("target", t).
alpar@756
    89
      edgeMap("label", label).
alpar@756
    90
      run();
alpar@756
    91
    check(countNodes(g) == 2,"There should be 2 nodes");
alpar@756
    92
    check(countEdges(g) == 2,"There should be 2 arcs");
alpar@756
    93
  }
alpar@756
    94
alpar@756
    95
  {
alpar@756
    96
    ListDigraph d; 
alpar@756
    97
    std::istringstream input(test_lgf_nomap);
alpar@756
    98
    digraphReader(d, input).
alpar@756
    99
      run();
alpar@756
   100
    check(countNodes(d) == 2,"There should be 2 nodes");
alpar@756
   101
    check(countArcs(d) == 1,"There should be 1 arc");
alpar@756
   102
  }
alpar@756
   103
  {
alpar@756
   104
    ListGraph g;
alpar@756
   105
    std::istringstream input(test_lgf_nomap);
alpar@756
   106
    graphReader(g, input).
alpar@756
   107
      run();
alpar@756
   108
    check(countNodes(g) == 2,"There should be 2 nodes");
alpar@756
   109
    check(countEdges(g) == 1,"There should be 1 edge");
alpar@756
   110
  }
alpar@756
   111
alpar@756
   112
  {
alpar@756
   113
    ListDigraph d; 
alpar@756
   114
    std::istringstream input(test_lgf_bad1);
alpar@756
   115
    bool ok=false;
alpar@756
   116
    try {
alpar@756
   117
      digraphReader(d, input).
alpar@756
   118
        run();
alpar@756
   119
    }
alpar@756
   120
    catch (FormatError& error) 
alpar@756
   121
      {
alpar@756
   122
        ok = true;
alpar@756
   123
      }
alpar@756
   124
    check(ok,"FormatError exception should have occured");
alpar@756
   125
  }
alpar@756
   126
  {
alpar@756
   127
    ListGraph g;
alpar@756
   128
    std::istringstream input(test_lgf_bad1);
alpar@756
   129
    bool ok=false;
alpar@756
   130
    try {
alpar@756
   131
      graphReader(g, input).
alpar@756
   132
        run();
alpar@756
   133
    }
alpar@756
   134
    catch (FormatError& error)
alpar@756
   135
      {
alpar@756
   136
        ok = true;
alpar@756
   137
      }
alpar@756
   138
    check(ok,"FormatError exception should have occured");
alpar@756
   139
  }
alpar@756
   140
alpar@756
   141
  {
alpar@756
   142
    ListDigraph d; 
alpar@756
   143
    std::istringstream input(test_lgf_bad2);
alpar@756
   144
    bool ok=false;
alpar@756
   145
    try {
alpar@756
   146
      digraphReader(d, input).
alpar@756
   147
        run();
alpar@756
   148
    }
alpar@756
   149
    catch (FormatError& error)
alpar@756
   150
      {
alpar@756
   151
        ok = true;
alpar@756
   152
      }
alpar@756
   153
    check(ok,"FormatError exception should have occured");
alpar@756
   154
  }
alpar@756
   155
  {
alpar@756
   156
    ListGraph g;
alpar@756
   157
    std::istringstream input(test_lgf_bad2);
alpar@756
   158
    bool ok=false;
alpar@756
   159
    try {
alpar@756
   160
      graphReader(g, input).
alpar@756
   161
        run();
alpar@756
   162
    }
alpar@756
   163
    catch (FormatError& error)
alpar@756
   164
      {
alpar@756
   165
        ok = true;
alpar@756
   166
      }
alpar@756
   167
    check(ok,"FormatError exception should have occured");
alpar@756
   168
  }
alpar@756
   169
}