aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp.test/src/MergeableHeap.cpp
diff options
context:
space:
mode:
authorcathook <b01902109@csie.ntu.edu.tw>2014-06-01 14:14:52 +0800
committercathook <b01902109@csie.ntu.edu.tw>2014-06-01 14:14:52 +0800
commit2d26b8e8d4383f34aa0a37b9d1754be76ba19602 (patch)
tree90da71e0aae685143f39128e15444d6ccdad042c /meowpp.test/src/MergeableHeap.cpp
parentbd7552bc352de4ff83c1d0365df8750c2bc4bf0a (diff)
downloadmeow-2d26b8e8d4383f34aa0a37b9d1754be76ba19602.tar
meow-2d26b8e8d4383f34aa0a37b9d1754be76ba19602.tar.gz
meow-2d26b8e8d4383f34aa0a37b9d1754be76ba19602.tar.bz2
meow-2d26b8e8d4383f34aa0a37b9d1754be76ba19602.tar.lz
meow-2d26b8e8d4383f34aa0a37b9d1754be76ba19602.tar.xz
meow-2d26b8e8d4383f34aa0a37b9d1754be76ba19602.tar.zst
meow-2d26b8e8d4383f34aa0a37b9d1754be76ba19602.zip
test...
Diffstat (limited to 'meowpp.test/src/MergeableHeap.cpp')
-rw-r--r--meowpp.test/src/MergeableHeap.cpp74
1 files changed, 0 insertions, 74 deletions
diff --git a/meowpp.test/src/MergeableHeap.cpp b/meowpp.test/src/MergeableHeap.cpp
deleted file mode 100644
index e8183ca..0000000
--- a/meowpp.test/src/MergeableHeap.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-#include "meowpp/dsa/MergeableHeap.h"
-#include "meowpp/utility.h"
-
-#include "dsa.h"
-
-#include <vector>
-#include <queue>
-#include <cstdlib>
-
-
-TEST(MergeableHeap, "..."){
- int N = 10;
- std::vector<std::priority_queue<int> > nhp;
- std::vector<meow::MergeableHeap<int> > mhp;
- for(int i = 0; i < 10; i++){
- int MM = 5000 + rand() % 10000;
- meow::messagePrintf(1, "%d-th test (M = %5d)", i, MM);
- nhp.clear(); nhp.resize(N);
- mhp.clear(); mhp.resize(N);
- int tn = 0, tm = 0, t0;
- for(int j = 0; j < MM; j++){
- if((rand() & 3) == 0){
- int a = rand() % N;
- int num = rand();
- t0 = clock(); nhp[a].push(num); tn += clock() - t0;
- t0 = clock(); mhp[a].push(num); tm += clock() - t0;
- }else if(rand() & 1){
- int a = rand() % N;
- t0 = clock();
- if(!nhp[a].empty()) nhp[a].pop();
- tn += clock() - t0;
- t0 = clock();
- if(!mhp[a].empty()) mhp[a].pop();
- tm += clock() - t0;
- }else{
- int a = rand() % N, b = rand() % N;
- if(b == a) b = (b + 1) % N;
- t0 = clock();
- for( ; !nhp[b].empty(); nhp[b].pop()){
- nhp[a].push(nhp[b].top());
- }
- tn += clock() - t0;
- t0 = clock();
- mhp[a].merge(&mhp[b]);
- tm += clock() - t0;
- }
- }
- bool ok = true;
- for(int j = 0; j < N; j++){
- while(!nhp[j].empty() && !mhp[j].empty()){
- if(nhp[j].top() != mhp[j].top()){
- ok = false;
- break;
- }
- nhp[j].pop();
- mhp[j].pop();
- }
- if(mhp[j].empty() != nhp[j].empty()){
- ok = false;
- }
- if(ok == false) break;
- }
- ok = true;
- if(!ok){
- meow::messagePrintf(-1, "fail");
- return false;
- }else{
- meow::messagePrintf(-1, "ok %.3f/%.3f",
- tm * 1.0 / CLOCKS_PER_SEC,
- tn * 1.0 / CLOCKS_PER_SEC );
- }
- }
- return true;
-}