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