summaryrefslogtreecommitdiff
path: root/core/test_multi_queue.cpp
blob: e9ff9b3d04308fe5635096294951bda7c5952b69 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <assert.h>
#include <iostream>
#include <stdlib.h>

#include <boost/mpl/vector.hpp>

#include "time.hpp"
#include "template_helpers.hpp"

// fake RuntimeID & AverageQueueLength wich is otherwise in "quant_types.hpp"
template<typename T>
struct RuntimeID {
  static const uint8_t value = T::runtimeId;
};

template<typename T>
struct AverageQueueSize {
  static const uint64_t value = T::aql;
};

template<typename T> struct Foo {
  Foo(int i) : val(i) {}
  int operator() () { return val; }
  int val;
  typedef T quant_t;
};

struct A { 
  static const unsigned char runtimeId = 0; 
  static const uint64_t aql = 1000; 
  static const char* const name;
};
const char* const A::name = "A";
struct B {
  static const unsigned char runtimeId = 1; 
  static const uint64_t aql = 2000;
  static const char* const name;
};
const char* const B::name = "B";
struct C { 
  static const unsigned char runtimeId = 2; 
  static const uint64_t aql = 3000;
  static const char* const name;
};
const char* const C::name = "C";

typedef boost::mpl::vector<A, B, C> DiscreteQuantorList;

// prevent quant_types to be included
#define sKmf7ztuNbBT3ua3iNX4k5rtsg0

#include "multi_queue.hpp"

#include "mempool.hpp"

using namespace std;

template<typename T>
void test(int line, int testid, T ex, T got) {
  if (ex != got) {
    cout << "line " << line
	 << ", test " << testid
	 << ", expected " << ex
	 << ", got " << got << endl;
    exit(-1);
  }
}

int main() {
  using boost::make_tuple;
  typedef MultiQueue<Time, Foo,
		     boost::mpl::list< A, B, C >
		     > mq_t;

  mq_t mq{};
  Time ct(0);

  // macro helpers
  //#define PMQ {for(int i=0; i<MultiQueueImpl::numRID;i++)cout<<mq.minVal[i] << " "; cout << endl;}
#define PMQ
#define I(v,q) { mq.insert<q>(ct,Time(v),10*v); PMQ }
#define T(v,q,command) {					\
    test(__LINE__, 1, mq.minType(), RuntimeID<q>::value);	\
    test(__LINE__, 2, mq.min(), Time(v));		     \
    test(__LINE__, 3, mq.get<q>()(ct).minVal(), Time(v));    \
    test(__LINE__, 4, mq.get<q>()(ct).minPayload()(), 10*v);	\
    mq.command<q>(ct); \
    PMQ \
  }
#define Tg(v,q) T(v,q,removeMin)
#define Tl(v,q) T(v,q,removeLocalMin)

  // test extractMin
  PMQ
  I(9,C);
  I(7,C);
  I(3,B);
  I(3,B);
  I(3,A);
  I(2,C);
  I(2,A);
  I(2,B);
  I(1,A);

  Tg(1,A);
  Tg(2,A);
  Tg(2,B);
  Tg(2,C);
  Tg(3,A);
  Tg(3,B);
  Tg(3,B);
  Tg(7,C);
  Tg(9,C);

  // test extractLocalMin
  PMQ
  I(9,C);
  I(7,C);
  I(3,B);
  I(3,B);
  I(3,A);
  I(2,C);
  I(2,A);
  I(2,B);
  I(1,A);

  Tl(1,A);
  Tl(2,A);
  Tl(2,B);
  Tl(2,C);
  Tl(3,A);
  Tl(3,B);
  Tl(3,B);
  Tl(7,C);
  Tl(9,C);

  // test extractLocalMin
  PMQ
  I(9,C);
  I(7,C);
  I(3,B);
  I(3,B);
  I(3,A);
  I(2,C);
  I(2,A);
  I(2,B);
  I(1,A);

  mq.removeLocalMin<B>(ct);
  Tl(1,A);
  Tl(2,A);
  //Tl(2,B);
  mq.removeLocalMin<A>(ct);
  Tl(2,C);
  //  Tl(3,A);
  Tl(3,B);
  Tl(3,B);
  Tl(7,C);
  Tl(9,C);


  // got until here -> success
  return 0;
}
contact: Jan Huwald // Impressum