diff options
author | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
commit | 420d2ef464d4a741028e132e662d5626806a41f5 (patch) | |
tree | 1aca6eb512e4ed0fb5f3c10c528cb998b6ffd695 /core/test_heap.cpp |
Diffstat (limited to 'core/test_heap.cpp')
-rw-r--r-- | core/test_heap.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/core/test_heap.cpp b/core/test_heap.cpp new file mode 100644 index 0000000..1ae79c2 --- /dev/null +++ b/core/test_heap.cpp @@ -0,0 +1,43 @@ +#include <iostream> +#include <stdlib.h> + + +template<typename Ignored> +struct AverageQueueSize { + static const uint64_t value = 0; // cause a crash if used +}; + +#include "priority_queue.hpp" +#include "heap.hpp" +#include "mempool.hpp" + +using namespace std; + +int main() { + int count = 1000; + typedef Heap<PriorityQueue<Time, double> > heap_t; + heap_t heap("test", count * 2 * sizeof(double)); + + // add many random values + for (int i=0; i<count; i++) { + heap(0).insert(Time(i), i); + } + + // retrieve them while continuing the passage of time, perhaps + // provoking an error ;-) + Time cur = 0; + for (int i=0; i<count; i++) { + Time n = heap(cur).minVal(); + if (n < cur) return -1; + cur = n; + heap(cur).removeMin(); + } + + // recap them again + for (int i=1; i<count; i++) { + if (!heap(Time(i)).isEmpty() && (heap(Time(i-1)).minPayload() > heap(Time(i)).minPayload())) return -1; + } + + // got until here -> success + return 0; +} |