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