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