summaryrefslogtreecommitdiff
path: root/core/test_heap.cpp
blob: 1ae79c274e681a81856b5ec3c108853c455146cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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