summaryrefslogtreecommitdiff
path: root/core/test_prioque.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/test_prioque.cpp')
-rw-r--r--core/test_prioque.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/core/test_prioque.cpp b/core/test_prioque.cpp
new file mode 100644
index 0000000..9457cd8
--- /dev/null
+++ b/core/test_prioque.cpp
@@ -0,0 +1,40 @@
+#include <assert.h>
+#include <iostream>
+#include <stdlib.h>
+
+#include "priority_queue.hpp"
+
+using namespace std;
+
+int main() {
+ // PQ is an open ended data structure -> alloc an arbitrary mem amount
+ PriorityQueue<unsigned int, unsigned int> *pq = new(malloc(1024 * 1024)) PriorityQueue<unsigned int, unsigned int>();
+
+ // macro helpers
+#define I(v) { uint s=pq->length; pq->insert(v,10*v); if (s+1 != pq->length) return -1; }
+#define T(v) { if (pq->minVal() != v || pq->minPayload() != 10*v) return -1; pq->removeMin(); }
+#define DP { for (uint i=0; i<pq->length; i++) { cout << pq->heap[i].val << ", "; } cout << "-" << endl; }
+ // add and remove some values
+ I(3);
+ I(2);
+ I(1);
+ T(1);
+ T(2);
+ T(3);
+
+ // add many random values
+ srand(42);
+ for (int i=0; i<100000; i++) {
+ // cout << ".";
+ pq->insert(rand(), 0);
+ }
+ unsigned int prev = 0;
+ for (int i=0; i<100000; i++) {
+ if (pq->minVal() < prev) return -1;
+ prev = pq->minVal();
+ pq->removeMin();
+ }
+
+ // got until here -> success
+ return 0;
+}
contact: Jan Huwald // Impressum