diff --git a/test/heap_test.cc b/test/heap_test.cc --- a/test/heap_test.cc +++ b/test/heap_test.cc @@ -25,14 +25,17 @@ #include <lemon/concepts/heap.h> #include <lemon/smart_graph.h> - #include <lemon/lgf_reader.h> #include <lemon/dijkstra.h> #include <lemon/maps.h> #include <lemon/bin_heap.h> +#include <lemon/quad_heap.h> +#include <lemon/dheap.h> #include <lemon/fib_heap.h> +#include <lemon/pairing_heap.h> #include <lemon/radix_heap.h> +#include <lemon/binomial_heap.h> #include <lemon/bucket_heap.h> #include "test_tools.h" @@ -89,18 +92,16 @@ template <typename Heap> void heapSortTest() { RangeMap<int> map(test_len, -1); - Heap heap(map); std::vector<int> v(test_len); - for (int i = 0; i < test_len; ++i) { v[i] = test_seq[i]; heap.push(i, v[i]); } std::sort(v.begin(), v.end()); for (int i = 0; i < test_len; ++i) { - check(v[i] == heap.prio() ,"Wrong order in heap sort."); + check(v[i] == heap.prio(), "Wrong order in heap sort."); heap.pop(); } } @@ -112,7 +113,6 @@ Heap heap(map); std::vector<int> v(test_len); - for (int i = 0; i < test_len; ++i) { v[i] = test_seq[i]; heap.push(i, v[i]); @@ -123,13 +123,11 @@ } std::sort(v.begin(), v.end()); for (int i = 0; i < test_len; ++i) { - check(v[i] == heap.prio() ,"Wrong order in heap increase test."); + check(v[i] == heap.prio(), "Wrong order in heap increase test."); heap.pop(); } } - - template <typename Heap> void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length, Node source) { @@ -144,7 +142,7 @@ Node t = digraph.target(a); if (dijkstra.reached(s)) { check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a], - "Error in a shortest path tree!"); + "Error in shortest path tree."); } } @@ -153,7 +151,7 @@ Arc a = dijkstra.predArc(n); Node s = digraph.source(a); check( dijkstra.dist(n) - dijkstra.dist(s) == length[a], - "Error in a shortest path tree!"); + "Error in shortest path tree."); } } @@ -175,6 +173,7 @@ node("source", source). run(); + // BinHeap { typedef BinHeap<Prio, ItemIntMap> IntHeap; checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); @@ -186,6 +185,93 @@ dijkstraHeapTest<NodeHeap>(digraph, length, source); } + // QuadHeap + { + typedef QuadHeap<Prio, ItemIntMap> IntHeap; + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); + heapSortTest<IntHeap>(); + heapIncreaseTest<IntHeap>(); + + typedef QuadHeap<Prio, IntNodeMap > NodeHeap; + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); + dijkstraHeapTest<NodeHeap>(digraph, length, source); + } + + // DHeap + { + typedef DHeap<Prio, ItemIntMap> IntHeap; + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); + heapSortTest<IntHeap>(); + heapIncreaseTest<IntHeap>(); + + typedef DHeap<Prio, IntNodeMap > NodeHeap; + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); + dijkstraHeapTest<NodeHeap>(digraph, length, source); + } + + // FibHeap + { + typedef FibHeap<Prio, ItemIntMap> IntHeap; + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); + heapSortTest<IntHeap>(); + heapIncreaseTest<IntHeap>(); + + typedef FibHeap<Prio, IntNodeMap > NodeHeap; + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); + dijkstraHeapTest<NodeHeap>(digraph, length, source); + } + + // PairingHeap + { + typedef PairingHeap<Prio, ItemIntMap> IntHeap; + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); + heapSortTest<IntHeap>(); + heapIncreaseTest<IntHeap>(); + + typedef PairingHeap<Prio, IntNodeMap > NodeHeap; + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); + dijkstraHeapTest<NodeHeap>(digraph, length, source); + } + + // RadixHeap + { + typedef RadixHeap<ItemIntMap> IntHeap; + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); + heapSortTest<IntHeap>(); + heapIncreaseTest<IntHeap>(); + + typedef RadixHeap<IntNodeMap > NodeHeap; + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); + dijkstraHeapTest<NodeHeap>(digraph, length, source); + } + + // BinomialHeap + { + typedef BinomialHeap<Prio, ItemIntMap> IntHeap; + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); + heapSortTest<IntHeap>(); + heapIncreaseTest<IntHeap>(); + + typedef BinomialHeap<Prio, IntNodeMap > NodeHeap; + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); + dijkstraHeapTest<NodeHeap>(digraph, length, source); + } + + // BucketHeap, SimpleBucketHeap + { + typedef BucketHeap<ItemIntMap> IntHeap; + checkConcept<Heap<Prio, ItemIntMap>, IntHeap>(); + heapSortTest<IntHeap>(); + heapIncreaseTest<IntHeap>(); + + typedef BucketHeap<IntNodeMap > NodeHeap; + checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>(); + dijkstraHeapTest<NodeHeap>(digraph, length, source); + + typedef SimpleBucketHeap<ItemIntMap> SimpleIntHeap; + heapSortTest<SimpleIntHeap>(); + } + { typedef FibHeap<Prio, ItemIntMap> IntHeap; checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();