summaryrefslogtreecommitdiff
path: root/core/test_multi_queue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/test_multi_queue.cpp')
-rw-r--r--core/test_multi_queue.cpp164
1 files changed, 164 insertions, 0 deletions
diff --git a/core/test_multi_queue.cpp b/core/test_multi_queue.cpp
new file mode 100644
index 0000000..e9ff9b3
--- /dev/null
+++ b/core/test_multi_queue.cpp
@@ -0,0 +1,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