summaryrefslogtreecommitdiff
path: root/core/test_heap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/test_heap.cpp')
-rw-r--r--core/test_heap.cpp43
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;
+}
contact: Jan Huwald // Impressum