X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=tests%2Ftest_wvtree02.cpp;fp=tests%2Ftest_wvtree02.cpp;h=9b49aca206a356b43f30207af1b55dea66bffc6b;hb=3fd4bcef236556c7f3bff1d2be8d3f4206245501;hp=0000000000000000000000000000000000000000;hpb=dc7a566a39187bfcea70737cda7278f858cd9842;p=SXSI%2Flibcds.git diff --git a/tests/test_wvtree02.cpp b/tests/test_wvtree02.cpp new file mode 100644 index 0000000..9b49aca --- /dev/null +++ b/tests/test_wvtree02.cpp @@ -0,0 +1,144 @@ + +#include +#include +#include +#include +#include +#include +#include + +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; + return 0; + } + struct stat text_info; + if(stat(argv[1],&text_info)<0) { + cout << "could not stat: " << argv[1] << endl; + return -1; + } + + uint samp; + { + stringstream ss; + ss << string(argv[2]); + + ss >> samp; + } + + uint n= (uint)text_info.st_size; + uint * text = new uint[n+1]; + FILE * fp = fopen(argv[1],"r"); + if(fp==NULL) { + cout << "could not open " << argv[1] << endl; + return -1; + } + + cout << "File: " << argv[1] << endl; + cout << "Length: " << n << endl; + + uint max_symbol = 0; + for(uint i=0;isave(fp) << endl; + fclose(fp); + delete wt; + fp = fopen(fname,"r"); + wt = static_sequence::load(fp); + fclose(fp); + delete [] fname; + + test_static_sequence(text,n,wt); + + cout << "WT Size: " << wt->size() << endl; + cout << "ft = " << 1.*wt->size()/n << endl; + + fname = new char[10+string(argv[1]).length()]; + sprintf(fname,"%s.wt",argv[1]); + fp = fopen(fname,"w"); + cout << "save: " << wt->save(fp) << endl; + fclose(fp); + delete [] fname; + + delete [] text; + delete wt; + +}