From 2d26b8e8d4383f34aa0a37b9d1754be76ba19602 Mon Sep 17 00:00:00 2001 From: cathook Date: Sun, 1 Jun 2014 14:14:52 +0800 Subject: test... --- meowpp.test/src/MergeableHeap.cpp | 74 --------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 meowpp.test/src/MergeableHeap.cpp (limited to 'meowpp.test/src/MergeableHeap.cpp') 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 -#include -#include - - -TEST(MergeableHeap, "..."){ - int N = 10; - std::vector > nhp; - std::vector > 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; -} -- cgit v1.2.3