#include "gqf.h" #include /* printf, scanf, puts, NULL */ #include #include #include "catch.hpp" #include #include #include "utils.h" using namespace std; TEST_CASE( "Merging mqf") { QF cf,cf1,cf2; QFi cfi; uint64_t qbits = 18; uint64_t small_qbits=qbits; uint64_t nhashbits = qbits + 8; uint64_t small_nhashbits=small_qbits+8; uint64_t nslots = (1ULL << qbits); uint64_t small_nslots=(1ULL << small_qbits); uint64_t nvals = 250*nslots/1000; uint64_t *vals; uint64_t counter_size=3; /* Initialise the CQF */ INFO("Initialize first cqf size ="<range; if(i%2==1){ qf_insert(&cf2, vals[i], 50,false,false); } else{ qf_insert(&cf1, vals[i], 50,false,false); } } qf_merge(&cf1,&cf2,&cf); for (uint64_t i = (nvals*2)/3; i range; qf_insert(&cf, vals[i], 50,false,false); } for (uint64_t i = 0; i < nvals; i++) { uint64_t count = qf_count_key(&cf, vals[i]%cf.metadata->range); CHECK(count>=50); } /* Initialize an iterator */ qf_iterator(&cf, &cfi, 0); do { uint64_t key, value, count; qfi_get(&cfi, &key, &value, &count); CHECK(count>=50); } while(!qfi_next(&cfi)); } TEST_CASE( "Merging Exception") { QF cf,cf1,cf2; QFi cfi; qf_init(&cf, 256, 15, 0,1,0, true, "", 2038074761); qf_init(&cf1, 256, 16, 0,1,0, true, "", 2038074761); qf_init(&cf2, 512, 17, 0,1,0, true, "", 2038074761); /* Generate random values */ REQUIRE_THROWS(qf_merge(&cf,&cf1,&cf2)); } TEST_CASE( "resize Exception") { QF cf; QFi cfi; qf_init(&cf, 256, 15, 0,1,0, true, "", 2038074761); /* Generate random values */ REQUIRE_THROWS(qf_resize(&cf,30)); } TEST_CASE( "Resize test" ) { QF qf; int counter_size=2; srand (1); uint64_t qbits=16; uint64_t num_hash_bits=qbits+9; uint64_t maximum_count=(1ULL<range); nRepetitions[i]=(rand()%257)+1; } double loadFactor=(double)qf.metadata->noccupied_slots/(double)qf.metadata->nslots; uint64_t insertedItems=0; while(insertedItemsnoccupied_slots/(double)qf.metadata->nslots; REQUIRE(new_occupied_size= nRepetitions[i]); } qf_destroy(&qf); } TEST_CASE( "comparing mqf") { QF cf,cf1,cf2; QFi cfi; uint64_t qbits = 18; uint64_t small_qbits=qbits; uint64_t nhashbits = qbits + 8; uint64_t small_nhashbits=small_qbits+8; uint64_t nslots = (1ULL << qbits); uint64_t small_nslots=(1ULL << small_qbits); uint64_t nvals = 250*nslots/1000; uint64_t *vals; uint64_t counter_size=3; /* Initialise the CQF */ INFO("Initialize first cqf size ="<range; if(i%2==1){ qf_insert(&cf2, vals[i], 50,false,false); qf_insert(&cf, vals[i], 50,false,false); } else{ qf_insert(&cf1, vals[i], 50,false,false); } } REQUIRE(qf_equals(&cf,&cf2)==true); REQUIRE(qf_equals(&cf1,&cf2)==false); } TEST_CASE( "intersect") { QF cf,cf1,cf2,cf3; QFi cfi; uint64_t qbits = 5; uint64_t small_qbits=qbits; uint64_t nhashbits = qbits + 15; uint64_t small_nhashbits=small_qbits+15; uint64_t nslots = (1ULL << qbits); uint64_t small_nslots=(1ULL << small_qbits); uint64_t nvals = 250*nslots/1000; uint64_t *vals; uint64_t counter_size=3; /* Initialise the CQF */ INFO("Initialize first cqf size ="<range); for(uint64_t j=0;jrange; if(i%3==0){ qf_insert(&cf, vals[i], 50,false,false); } else if(i%3==1){ qf_insert(&cf1, vals[i], 50,false,false); } else{ qf_insert(&cf, vals[i], 50,false,false); qf_insert(&cf1, vals[i], 50,false,false); qf_insert(&cf2, vals[i], 50,false,false); } } qf_intersect(&cf1,&cf,&cf3); // printf("CF\n" ); // qf_dump(&cf); // // printf("CF1\n" ); // qf_dump(&cf1); // // printf("CF2\n" ); // qf_dump(&cf2); // // printf("CF3\n" ); // qf_dump(&cf3); // REQUIRE(qf_equals(&cf2,&cf3)==true); } TEST_CASE( "subtract") { QF cf,cf1,cf2,cf3; QFi cfi; uint64_t qbits = 18; uint64_t small_qbits=qbits; uint64_t nhashbits = qbits + 15; uint64_t small_nhashbits=small_qbits+15; uint64_t nslots = (1ULL << qbits); uint64_t small_nslots=(1ULL << small_qbits); uint64_t nvals = 250*nslots/1000; uint64_t *vals; uint64_t counter_size=3; /* Initialise the CQF */ INFO("Initialize first cqf size ="<range); for(uint64_t j=0;jrange; qf_insert(&cf, vals[i], 100,false,false); qf_insert(&cf1, vals[i], 50,false,false); qf_insert(&cf2, vals[i], 50,false,false); } qf_subtract(&cf,&cf1,&cf3); // printf("CF\n" ); // qf_dump(&cf); // // printf("CF1\n" ); // qf_dump(&cf1); // // printf("CF2\n" ); // qf_dump(&cf2); // // printf("CF3\n" ); // qf_dump(&cf3); REQUIRE(qf_equals(&cf2,&cf3)==true); } TEST_CASE( "Multi Merging mqf") { QF cf2,correctCF; QF **cf; int nqf=10; QFi cfi; uint64_t qbits = 18; uint64_t small_qbits=qbits; uint64_t nhashbits = qbits + 8; uint64_t small_nhashbits=small_qbits+8; uint64_t nslots = (1ULL << qbits); uint64_t small_nslots=(1ULL << small_qbits); uint64_t nvals = 250*nslots/1000; uint64_t *vals; uint64_t counter_size=3; /* Initialise the CQF */ cf=new QF*[nqf]; for(int i=0;imetadata->labels_map->find(value); string t=""; for(auto f:iit->second) { t+=(char)(f+49); t+=';'; } INFO("label "<second) { CHECK(vals[i]%(f+1)==0); } } /* Initialize an iterator */ qf_iterator(cf[0], &cfi, 0); do { qfi_get(&cfi, &key, &value, &count); auto iit=cf[0]->metadata->labels_map->find(value); INFO("Key "<second) { CHECK(key%(f+1)==0); } } while(!qfi_next(&cfi)); }