1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/lgf_test.cc Thu Aug 04 21:19:55 2011 +0200
1.3 @@ -0,0 +1,169 @@
1.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library.
1.7 + *
1.8 + * Copyright (C) 2003-2011
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include <lemon/list_graph.h>
1.23 +#include <lemon/lgf_reader.h>
1.24 +#include "test_tools.h"
1.25 +
1.26 +using namespace lemon;
1.27 +
1.28 +char test_lgf[] =
1.29 + "@nodes\n"
1.30 + "label\n"
1.31 + "0\n"
1.32 + "1\n"
1.33 + "@arcs\n"
1.34 + " label\n"
1.35 + "0 1 0\n"
1.36 + "1 0 1\n"
1.37 + "@attributes\n"
1.38 + "source 0\n"
1.39 + "target 1\n";
1.40 +
1.41 +char test_lgf_nomap[] =
1.42 + "@nodes\n"
1.43 + "label\n"
1.44 + "0\n"
1.45 + "1\n"
1.46 + "@arcs\n"
1.47 + " -\n"
1.48 + "0 1\n";
1.49 +
1.50 +char test_lgf_bad1[] =
1.51 + "@nodes\n"
1.52 + "label\n"
1.53 + "0\n"
1.54 + "1\n"
1.55 + "@arcs\n"
1.56 + " - another\n"
1.57 + "0 1\n";
1.58 +
1.59 +char test_lgf_bad2[] =
1.60 + "@nodes\n"
1.61 + "label\n"
1.62 + "0\n"
1.63 + "1\n"
1.64 + "@arcs\n"
1.65 + " label -\n"
1.66 + "0 1\n";
1.67 +
1.68 +
1.69 +int main()
1.70 +{
1.71 + {
1.72 + ListDigraph d;
1.73 + ListDigraph::Node s,t;
1.74 + ListDigraph::ArcMap<int> label(d);
1.75 + std::istringstream input(test_lgf);
1.76 + digraphReader(d, input).
1.77 + node("source", s).
1.78 + node("target", t).
1.79 + arcMap("label", label).
1.80 + run();
1.81 + check(countNodes(d) == 2,"There should be 2 nodes");
1.82 + check(countArcs(d) == 2,"There should be 2 arcs");
1.83 + }
1.84 + {
1.85 + ListGraph g;
1.86 + ListGraph::Node s,t;
1.87 + ListGraph::EdgeMap<int> label(g);
1.88 + std::istringstream input(test_lgf);
1.89 + graphReader(g, input).
1.90 + node("source", s).
1.91 + node("target", t).
1.92 + edgeMap("label", label).
1.93 + run();
1.94 + check(countNodes(g) == 2,"There should be 2 nodes");
1.95 + check(countEdges(g) == 2,"There should be 2 arcs");
1.96 + }
1.97 +
1.98 + {
1.99 + ListDigraph d;
1.100 + std::istringstream input(test_lgf_nomap);
1.101 + digraphReader(d, input).
1.102 + run();
1.103 + check(countNodes(d) == 2,"There should be 2 nodes");
1.104 + check(countArcs(d) == 1,"There should be 1 arc");
1.105 + }
1.106 + {
1.107 + ListGraph g;
1.108 + std::istringstream input(test_lgf_nomap);
1.109 + graphReader(g, input).
1.110 + run();
1.111 + check(countNodes(g) == 2,"There should be 2 nodes");
1.112 + check(countEdges(g) == 1,"There should be 1 edge");
1.113 + }
1.114 +
1.115 + {
1.116 + ListDigraph d;
1.117 + std::istringstream input(test_lgf_bad1);
1.118 + bool ok=false;
1.119 + try {
1.120 + digraphReader(d, input).
1.121 + run();
1.122 + }
1.123 + catch (FormatError& error)
1.124 + {
1.125 + ok = true;
1.126 + }
1.127 + check(ok,"FormatError exception should have occured");
1.128 + }
1.129 + {
1.130 + ListGraph g;
1.131 + std::istringstream input(test_lgf_bad1);
1.132 + bool ok=false;
1.133 + try {
1.134 + graphReader(g, input).
1.135 + run();
1.136 + }
1.137 + catch (FormatError& error)
1.138 + {
1.139 + ok = true;
1.140 + }
1.141 + check(ok,"FormatError exception should have occured");
1.142 + }
1.143 +
1.144 + {
1.145 + ListDigraph d;
1.146 + std::istringstream input(test_lgf_bad2);
1.147 + bool ok=false;
1.148 + try {
1.149 + digraphReader(d, input).
1.150 + run();
1.151 + }
1.152 + catch (FormatError& error)
1.153 + {
1.154 + ok = true;
1.155 + }
1.156 + check(ok,"FormatError exception should have occured");
1.157 + }
1.158 + {
1.159 + ListGraph g;
1.160 + std::istringstream input(test_lgf_bad2);
1.161 + bool ok=false;
1.162 + try {
1.163 + graphReader(g, input).
1.164 + run();
1.165 + }
1.166 + catch (FormatError& error)
1.167 + {
1.168 + ok = true;
1.169 + }
1.170 + check(ok,"FormatError exception should have occured");
1.171 + }
1.172 +}