summaryrefslogtreecommitdiff
path: root/selftest.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-09-03 17:33:06 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-09-03 17:33:06 -0700
commitda9a720c3fc2d69e35f393fbb96a716599ac0a6f (patch)
tree2846189a0c20e3a54adf330b1f22ca584073d46e /selftest.cpp
parent4838cbc350a7608ebe345a821ef32bb01a8aeca7 (diff)
downloadinfinitytier-da9a720c3fc2d69e35f393fbb96a716599ac0a6f.tar.gz
infinitytier-da9a720c3fc2d69e35f393fbb96a716599ac0a6f.zip
Hash table bug fix, and add copy constructor and assignment operator for principle of least surprise.
Diffstat (limited to 'selftest.cpp')
-rw-r--r--selftest.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/selftest.cpp b/selftest.cpp
index 15afe52e..5e3b620b 100644
--- a/selftest.cpp
+++ b/selftest.cpp
@@ -581,31 +581,60 @@ static int testOther()
{
std::cout << "[other] Testing Hashtable... "; std::cout.flush();
{
- Hashtable<uint64_t,std::string> ht(128);
+ Hashtable<uint64_t,std::string> ht;
+ Hashtable<uint64_t,std::string> ht2;
std::map<uint64_t,std::string> ref; // assume std::map works correctly :)
for(int x=0;x<2;++x) {
for(int i=0;i<25000;++i) {
uint64_t k = rand();
while ((k == 0)||(ref.count(k) > 0))
++k;
- std::string v;
+ std::string v("!");
for(int j=0;j<(int)(k % 64);++j)
v.push_back("0123456789"[rand() % 10]);
ht.set(k,v);
ref[k] = v;
}
if (ht.size() != ref.size()) {
- std::cout << "FAILED! (size mismatch)" << std::endl;
+ std::cout << "FAILED! (size mismatch, original)" << std::endl;
+ return -1;
+ }
+ ht2 = ht;
+ Hashtable<uint64_t,std::string> ht3(ht2);
+ if (ht2.size() != ref.size()) {
+ std::cout << "FAILED! (size mismatch, assigned)" << std::endl;
+ return -1;
+ }
+ if (ht3.size() != ref.size()) {
+ std::cout << "FAILED! (size mismatch, copied)" << std::endl;
return -1;
}
for(std::map<uint64_t,std::string>::iterator i(ref.begin());i!=ref.end();++i) {
std::string *v = ht.get(i->first);
if (!v) {
- std::cout << "FAILED! (key not found)" << std::endl;
+ std::cout << "FAILED! (key " << i->first << " not found, original)" << std::endl;
+ return -1;
+ }
+ if (*v != i->second) {
+ std::cout << "FAILED! (key " << i->first << " not equal, original)" << std::endl;
+ return -1;
+ }
+ v = ht2.get(i->first);
+ if (!v) {
+ std::cout << "FAILED! (key " << i->first << " not found, assigned)" << std::endl;
+ return -1;
+ }
+ if (*v != i->second) {
+ std::cout << "FAILED! (key " << i->first << " not equal, assigned)" << std::endl;
+ return -1;
+ }
+ v = ht3.get(i->first);
+ if (!v) {
+ std::cout << "FAILED! (key " << i->first << " not found, copied)" << std::endl;
return -1;
}
if (*v != i->second) {
- std::cout << "FAILED! (key not equal)" << std::endl;
+ std::cout << "FAILED! (key " << i->first << " not equal, copied)" << std::endl;
return -1;
}
}