X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=libcds%2Ftests%2Ftest_wvtree01.cpp;h=ffd09c37254de700c4c7beffed6c31d87d8222a0;hb=44dc45dfa812b495fc4ef7dff7f69a6b89ee5128;hp=48f69511b3fcadfabfbc7028bdee2ecc0079fd5e;hpb=0bf9688e2615a9fc07860c5762240e4ce26ee5d3;p=SXSI%2FXMLTree.git diff --git a/libcds/tests/test_wvtree01.cpp b/libcds/tests/test_wvtree01.cpp index 48f6951..ffd09c3 100644 --- a/libcds/tests/test_wvtree01.cpp +++ b/libcds/tests/test_wvtree01.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; @@ -60,7 +107,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()]; @@ -74,7 +123,8 @@ int main(int argc, char ** argv) { fclose(fp); delete [] fname; - + test_static_sequence(text,n,wt); + cout << "WT Size: " << wt->size() << endl; cout << "ft = " << 1.*wt->size()/(bits(max_symbol-1)*n/8) << endl;