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