X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=libcds%2Ftests%2Ftest_wvtree02.cpp;h=9b49aca206a356b43f30207af1b55dea66bffc6b;hb=e38bc834442d5369a523ba47d74865e48995ace4;hp=8a76c727d406391b964279c93e10bb3324f220f0;hpb=0bf9688e2615a9fc07860c5762240e4ce26ee5d3;p=SXSI%2FXMLTree.git diff --git a/libcds/tests/test_wvtree02.cpp b/libcds/tests/test_wvtree02.cpp index 8a76c72..9b49aca 100644 --- a/libcds/tests/test_wvtree02.cpp +++ b/libcds/tests/test_wvtree02.cpp @@ -9,6 +9,53 @@ using namespace std; +void test_static_sequence(uint * symbols, uint n, static_sequence * ss) { + cout << "Size: " << ss->size() << endl; + uint max_v=0; + for(uint i=0;iaccess(i); + uint r = ss->rank(symbols[i],i); + uint s = ss->select(symbols[i],occ[symbols[i]]); + uint rM1 = (i==0)?0:ss->rank(symbols[i],i-1); + if(r!=occ[symbols[i]]) { + cout << "Error in rank for symbol " << symbols[i] << " at position " << i << endl; + cout << "value: " << r << endl; + cout << "Expected: " << occ[symbols[i]] << endl; + error = true; + } + if(s!=i) { + cout << "Error in select for symbol " << symbols[i] << " at position " << occ[symbols[i]] << endl; + cout << "value: " << s << endl; + cout << "Expected: " << i << endl; + error = true; + } + if(a!=symbols[i]) { + cout << "Error in access at position " << i << endl; + cout << "value: " << a << endl; + cout << "Expected: " << symbols[i] << endl; + error = true; + } + if(rM1!=occ[symbols[i]]-1) { + cout << "Error in rankM1 for symbol " << symbols[i] << " at position " << i-1 << endl; + cout << "value: " << rM1 << endl; + cout << "Expected: " << occ[symbols[i]]-1 << endl; + error = true; + } + } + if(!error) + cout << "Test OK! It works :)" << endl; + delete [] occ; +} + int main(int argc, char ** argv) { if(argc!=3) { cout << "usage: " << argv[0] << " " << endl; @@ -63,7 +110,9 @@ int main(int argc, char ** argv) { cout << "Building Huffman table..."; cout.flush(); wt_coder * wtc = new wt_coder_huff(text,n,am); cout << "done" << endl; cout.flush(); - static_sequence * wt = new static_sequence_wvtree(text,n,wtc,bmb,am,true); + cout << "Building static_sequence..."; cout.flush(); + static_sequence * wt = new static_sequence_wvtree(text,n,wtc,bmb,am); + cout << "done" << endl; cout.flush(); delete bmb; char * fname = new char[10+string(argv[1]).length()]; @@ -77,7 +126,7 @@ int main(int argc, char ** argv) { fclose(fp); delete [] fname; - ((static_sequence_wvtree*)wt)->test_structure(text,n); + test_static_sequence(text,n,wt); cout << "WT Size: " << wt->size() << endl; cout << "ft = " << 1.*wt->size()/n << endl;