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