test/heap_test.cc
changeset 1435 8e85e6bbefdf
parent 1330 52ef02524468
child 1728 eb8bb91ba9e2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/heap_test.cc	Mon May 23 04:48:14 2005 +0000
     1.3 @@ -0,0 +1,98 @@
     1.4 +// -*- c++ -*-
     1.5 +
     1.6 +#include <iostream>
     1.7 +#include <fstream>
     1.8 +#include <string>
     1.9 +#include <vector>
    1.10 +
    1.11 +#include <lemon/concept_check.h>
    1.12 +#include <lemon/concept/heap.h>
    1.13 +
    1.14 +#include <lemon/smart_graph.h>
    1.15 +
    1.16 +#include <lemon/graph_reader.h>
    1.17 +
    1.18 +#include <lemon/bin_heap.h>
    1.19 +#include <lemon/fib_heap.h>
    1.20 +#include <lemon/radix_heap.h>
    1.21 +
    1.22 +#include "test_tools.h"
    1.23 +
    1.24 +#include "heap_test.h"
    1.25 +
    1.26 +
    1.27 +using namespace lemon;
    1.28 +using namespace lemon::concept;
    1.29 +
    1.30 +
    1.31 +int main() {
    1.32 +
    1.33 +  typedef int Item;
    1.34 +  typedef int Prio;
    1.35 +  typedef IntIntMap ItemIntMap;
    1.36 +
    1.37 +  typedef ListGraph Graph;
    1.38 +
    1.39 +  typedef Graph::Edge Edge;
    1.40 +  typedef Graph::Node Node;
    1.41 +  typedef Graph::EdgeIt EdgeIt;
    1.42 +  typedef Graph::NodeIt NodeIt;
    1.43 +  typedef Graph::EdgeMap<int> LengthMap;
    1.44 +
    1.45 +  Graph graph;
    1.46 +  LengthMap length(graph);
    1.47 +  Node start;
    1.48 +
    1.49 +  /// \todo create own test graph
    1.50 +
    1.51 +  std::string f_name;
    1.52 +  if( getenv("srcdir") )
    1.53 +    f_name = std::string(getenv("srcdir"));
    1.54 +  else f_name = ".";
    1.55 +  f_name += "/dijkstra_test.lgf";
    1.56 +  
    1.57 +  std::ifstream input(f_name.c_str());
    1.58 +  check(input, "Input file '" << f_name << "' not found.");
    1.59 +  readGraph(input, graph, length, start);  
    1.60 + 
    1.61 +  {
    1.62 +    std::cerr << "Checking Bin Heap" << std::endl;
    1.63 +
    1.64 +    typedef BinHeap<Item, Prio, ItemIntMap> IntHeap;
    1.65 +    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
    1.66 +    heapSortTest<IntHeap>(100);
    1.67 +    heapIncreaseTest<IntHeap>(100);
    1.68 +    
    1.69 +    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
    1.70 +    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
    1.71 +    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
    1.72 +  }
    1.73 +  {
    1.74 +    std::cerr << "Checking Fib Heap" << std::endl;
    1.75 +
    1.76 +    typedef FibHeap<Item, Prio, ItemIntMap> IntHeap;
    1.77 +    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
    1.78 +    heapSortTest<IntHeap>(100);
    1.79 +    heapIncreaseTest<IntHeap>(100);
    1.80 +
    1.81 +    typedef FibHeap<Node, Prio, Graph::NodeMap<int> > NodeHeap;
    1.82 +    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
    1.83 +    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
    1.84 +  }
    1.85 +  {
    1.86 +    std::cerr << "Checking Radix Heap" << std::endl;
    1.87 +
    1.88 +    typedef RadixHeap<Item, ItemIntMap> IntHeap;
    1.89 +    checkConcept<Heap<Item, Prio, ItemIntMap>, IntHeap>();
    1.90 +    heapSortTest<IntHeap>(100);
    1.91 +    heapIncreaseTest<IntHeap>(100);
    1.92 +
    1.93 +    typedef RadixHeap<Node, Graph::NodeMap<int> > NodeHeap;
    1.94 +    checkConcept<Heap<Node, Prio, Graph::NodeMap<int> >, NodeHeap>();
    1.95 +    dijkstraHeapTest<Graph, LengthMap, NodeHeap>(graph, length, start);
    1.96 +  }
    1.97 +
    1.98 +  std::cout << __FILE__ ": All tests passed.\n";
    1.99 +
   1.100 +  return 0;
   1.101 +}