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