Make sure index test can handle n = 0

Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
Anna Schumaker 2014-03-25 17:48:55 -04:00 committed by Anna Schumaker
parent 7490b98db6
commit d452177f32
2 changed files with 27 additions and 5 deletions

View File

@ -34,6 +34,8 @@ function run_test
fi
}
run_test 0
echo
run_test 10
echo
run_test 100

View File

@ -24,6 +24,11 @@ void test_results(bool success, unsigned int line)
test_num++;
}
void test_size(Index &index, unsigned int expected, unsigned int line)
{
test_results(index.size() == expected, line);
}
int main(int argc, char **argv)
{
bool autosave = false;
@ -72,7 +77,7 @@ int main(int argc, char **argv)
index.insert(key, i);
}
test_results(index.size() == 26, __LINE__);
test_size(index, (n == 0) ? 1 : 26, __LINE__);
/**
@ -81,7 +86,12 @@ int main(int argc, char **argv)
for (c = 'a'; c <= 'z'; c++) {
std::string key = "";
key += c;
if (index.find(key)->values.size() != n)
IndexEntry *it = index.find(key);
if (n == 0 && c > 'a') {
if (it != NULL)
test_results(false, __LINE__);
} else if (it->values.size() != n)
test_results(false, __LINE__);
}
test_results(true, __LINE__);
@ -97,11 +107,15 @@ int main(int argc, char **argv)
for (unsigned int i = 0; i < n; i++)
index.remove(key, i);
if (index.find(key)->values.size() > 0)
IndexEntry *it = index.find(key);
if (n == 0 && c > 'a') {
if (it != NULL)
test_results(false, __LINE__);
} else if (it->values.size() != 0)
test_results(false, __LINE__);
}
test_results(index.size() == 26, __LINE__);
test_size(index, (n == 0) ? 1 : 26, __LINE__);
/**
@ -127,7 +141,13 @@ int main(int argc, char **argv)
std::string key = "";
key += c;
if (index.find(key)->values.size() != index2.find(key)->values.size())
IndexEntry *it1 = index.find(key);
IndexEntry *it2 = index2.find(key);
if (n == 0 && c > 'a') {
if (it1 != NULL || it2 != NULL)
test_results(false, __LINE__);
} else if (it1->values.size() != it2->values.size())
test_results(false, __LINE__);
}
test_results(true, __LINE__);