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