alpar@756: /* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@756:  *
alpar@756:  * This file is a part of LEMON, a generic C++ optimization library.
alpar@756:  *
alpar@756:  * Copyright (C) 2003-2011
alpar@756:  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@756:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@756:  *
alpar@756:  * Permission to use, modify and distribute this software is granted
alpar@756:  * provided that this copyright notice appears in all copies. For
alpar@756:  * precise terms see the accompanying LICENSE file.
alpar@756:  *
alpar@756:  * This software is provided "AS IS" with no warranty of any kind,
alpar@756:  * express or implied, and with no claim as to its suitability for any
alpar@756:  * purpose.
alpar@756:  *
alpar@756:  */
alpar@756: 
alpar@756: #include <lemon/list_graph.h>
alpar@756: #include <lemon/lgf_reader.h>
alpar@756: #include "test_tools.h"
alpar@756: 
alpar@756: using namespace lemon;
alpar@756: 
alpar@756: char test_lgf[] =
alpar@756:   "@nodes\n"
alpar@756:   "label\n"
alpar@756:   "0\n"
alpar@756:   "1\n"
alpar@756:   "@arcs\n"
alpar@756:   "     label\n"
alpar@756:   "0 1  0\n"
alpar@756:   "1 0  1\n"
alpar@756:   "@attributes\n"
alpar@756:   "source 0\n"
alpar@756:   "target 1\n";
alpar@756: 
alpar@756: char test_lgf_nomap[] =
alpar@756:   "@nodes\n"
alpar@756:   "label\n"
alpar@756:   "0\n"
alpar@756:   "1\n"
alpar@756:   "@arcs\n"
alpar@756:   "     -\n"
alpar@756:   "0 1\n";
alpar@756: 
alpar@756: char test_lgf_bad1[] =
alpar@756:   "@nodes\n"
alpar@756:   "label\n"
alpar@756:   "0\n"
alpar@756:   "1\n"
alpar@756:   "@arcs\n"
alpar@756:   "     - another\n"
alpar@756:   "0 1\n";
alpar@756: 
alpar@756: char test_lgf_bad2[] =
alpar@756:   "@nodes\n"
alpar@756:   "label\n"
alpar@756:   "0\n"
alpar@756:   "1\n"
alpar@756:   "@arcs\n"
alpar@756:   "     label -\n"
alpar@756:   "0 1\n";
alpar@756: 
alpar@756: 
alpar@756: int main() 
alpar@756: {
alpar@756:   {
alpar@756:     ListDigraph d; 
alpar@756:     ListDigraph::Node s,t;
alpar@756:     ListDigraph::ArcMap<int> label(d);
alpar@756:     std::istringstream input(test_lgf);
alpar@756:     digraphReader(d, input).
alpar@756:       node("source", s).
alpar@756:       node("target", t).
alpar@756:       arcMap("label", label).
alpar@756:       run();
alpar@756:     check(countNodes(d) == 2,"There should be 2 nodes");
alpar@756:     check(countArcs(d) == 2,"There should be 2 arcs");
alpar@756:   }
alpar@756:   {
alpar@756:     ListGraph g;
alpar@756:     ListGraph::Node s,t;
alpar@756:     ListGraph::EdgeMap<int> label(g);
alpar@756:     std::istringstream input(test_lgf);
alpar@756:     graphReader(g, input).
alpar@756:       node("source", s).
alpar@756:       node("target", t).
alpar@756:       edgeMap("label", label).
alpar@756:       run();
alpar@756:     check(countNodes(g) == 2,"There should be 2 nodes");
alpar@756:     check(countEdges(g) == 2,"There should be 2 arcs");
alpar@756:   }
alpar@756: 
alpar@756:   {
alpar@756:     ListDigraph d; 
alpar@756:     std::istringstream input(test_lgf_nomap);
alpar@756:     digraphReader(d, input).
alpar@756:       run();
alpar@756:     check(countNodes(d) == 2,"There should be 2 nodes");
alpar@756:     check(countArcs(d) == 1,"There should be 1 arc");
alpar@756:   }
alpar@756:   {
alpar@756:     ListGraph g;
alpar@756:     std::istringstream input(test_lgf_nomap);
alpar@756:     graphReader(g, input).
alpar@756:       run();
alpar@756:     check(countNodes(g) == 2,"There should be 2 nodes");
alpar@756:     check(countEdges(g) == 1,"There should be 1 edge");
alpar@756:   }
alpar@756: 
alpar@756:   {
alpar@756:     ListDigraph d; 
alpar@756:     std::istringstream input(test_lgf_bad1);
alpar@756:     bool ok=false;
alpar@756:     try {
alpar@756:       digraphReader(d, input).
alpar@756:         run();
alpar@756:     }
kpeter@764:     catch (FormatError&) 
alpar@756:       {
alpar@756:         ok = true;
alpar@756:       }
alpar@756:     check(ok,"FormatError exception should have occured");
alpar@756:   }
alpar@756:   {
alpar@756:     ListGraph g;
alpar@756:     std::istringstream input(test_lgf_bad1);
alpar@756:     bool ok=false;
alpar@756:     try {
alpar@756:       graphReader(g, input).
alpar@756:         run();
alpar@756:     }
kpeter@764:     catch (FormatError&)
alpar@756:       {
alpar@756:         ok = true;
alpar@756:       }
alpar@756:     check(ok,"FormatError exception should have occured");
alpar@756:   }
alpar@756: 
alpar@756:   {
alpar@756:     ListDigraph d; 
alpar@756:     std::istringstream input(test_lgf_bad2);
alpar@756:     bool ok=false;
alpar@756:     try {
alpar@756:       digraphReader(d, input).
alpar@756:         run();
alpar@756:     }
kpeter@764:     catch (FormatError&)
alpar@756:       {
alpar@756:         ok = true;
alpar@756:       }
alpar@756:     check(ok,"FormatError exception should have occured");
alpar@756:   }
alpar@756:   {
alpar@756:     ListGraph g;
alpar@756:     std::istringstream input(test_lgf_bad2);
alpar@756:     bool ok=false;
alpar@756:     try {
alpar@756:       graphReader(g, input).
alpar@756:         run();
alpar@756:     }
kpeter@764:     catch (FormatError&)
alpar@756:       {
alpar@756:         ok = true;
alpar@756:       }
alpar@756:     check(ok,"FormatError exception should have occured");
alpar@756:   }
alpar@756: }