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