/* -*- C++ -*-
 * src/test/graph_test.cc - Part of LEMON, a generic C++ optimization library
 *
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 * (Egervary Combinatorial Optimization Research Group, EGRES).
 *
 * Permission to use, modify and distribute this software is granted
 * provided that this copyright notice appears in all copies. For
 * precise terms see the accompanying LICENSE file.
 *
 * This software is provided "AS IS" with no warranty of any kind,
 * express or implied, and with no claim as to its suitability for any
 * purpose.
 *
 */

#include<iostream>
#include<lemon/smart_graph.h>
#include<lemon/skeletons/graph.h>
#include<lemon/list_graph.h>
#include<lemon/full_graph.h>

#include"test_tools.h"
#include"graph_test.h"

/**
\file
This test makes consistency checks of list graph structures.

G.addNode(), G.addEdge(), G.tail(), G.head()

\todo Checks for empty graphs and isolated points.
conversion.
*/

using namespace lemon;

template<class Graph> void bidirPetersen(Graph &G)
{
  typedef typename Graph::Edge Edge;
  typedef typename Graph::EdgeIt EdgeIt;
  
  checkGraphEdgeList(G,15);
  
  std::vector<Edge> ee;
  
  for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);

  for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
    G.addEdge(G.head(*p),G.tail(*p));
}

template<class Graph> void checkPetersen(Graph &G)
{
  typedef typename Graph::Node Node;

  typedef typename Graph::EdgeIt EdgeIt;
  typedef typename Graph::NodeIt NodeIt;

  checkGraphNodeList(G,10);
  checkGraphEdgeList(G,30);

  for(NodeIt n(G);n!=INVALID;++n) {
    checkGraphInEdgeList(G,n,3);
    checkGraphOutEdgeList(G,n,3);
    ++n;
  }  
}

//Compile Graph
template void lemon::checkCompileStaticGraph<skeleton::StaticGraph>
(skeleton::StaticGraph &);

template void lemon::checkCompileGraph<skeleton::ExtendableGraph>
(skeleton::ExtendableGraph &);

template void lemon::checkCompileErasableGraph<skeleton::ErasableGraph>
(skeleton::ErasableGraph &);

//Compile SmartGraph
template void lemon::checkCompileGraph<SmartGraph>(SmartGraph &);
template void lemon::checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);

//Compile SymSmartGraph
template void lemon::checkCompileGraph<SymSmartGraph>(SymSmartGraph &);
template void lemon::checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &);

//Compile ListGraph
template void lemon::checkCompileGraph<ListGraph>(ListGraph &);
template void lemon::checkCompileErasableGraph<ListGraph>(ListGraph &);
template void lemon::checkCompileGraphFindEdge<ListGraph>(ListGraph &);


//Compile SymListGraph
template void lemon::checkCompileGraph<SymListGraph>(SymListGraph &);
template void lemon::checkCompileErasableGraph<SymListGraph>(SymListGraph &);
template void lemon::checkCompileGraphFindEdge<SymListGraph>(SymListGraph &);

//Compile FullGraph
template void lemon::checkCompileStaticGraph<FullGraph>(FullGraph &);
template void lemon::checkCompileGraphFindEdge<FullGraph>(FullGraph &);

//Compile EdgeSet <ListGraph>
template void lemon::checkCompileGraph<EdgeSet <ListGraph> >
(EdgeSet <ListGraph> &);
template void lemon::checkCompileGraphEraseEdge<EdgeSet <ListGraph> >
(EdgeSet <ListGraph> &);
template void lemon::checkCompileGraphFindEdge<EdgeSet <ListGraph> >
(EdgeSet <ListGraph> &);

//Compile EdgeSet <NodeSet>
template void lemon::checkCompileGraph<EdgeSet <NodeSet> >(EdgeSet <NodeSet> &);
template void lemon::checkCompileGraphEraseEdge<EdgeSet <NodeSet> >
(EdgeSet <NodeSet> &);
template void lemon::checkCompileGraphFindEdge<EdgeSet <NodeSet> >
(EdgeSet <NodeSet> &);


int main() 
{
  {
    SmartGraph G;
    addPetersen(G);
    bidirPetersen(G);
    checkPetersen(G);
  }
  {
    ListGraph G;
    addPetersen(G);
    bidirPetersen(G);
    checkPetersen(G);
  }
  {
    SymSmartGraph G;
    addPetersen(G);
    checkPetersen(G);
  }
  {
    SymListGraph G;
    addPetersen(G);
    checkPetersen(G);
  }

  ///\file
  ///\todo map tests.
  ///\todo copy constr tests.

  std::cout << __FILE__ ": All tests passed.\n";

  return 0;
}
