Activity - Unit testing
Consider the simple one-function jhash
module used in Lab3 and the TSE.
It comprises jhash.c and jhash.h and implements the JenkinsHash()
function below.
- With your group, list all the tests a good unit test should run against this unit.
- Can you spot the bug? (I just noticed one I’d overlooked before.)
- If you have time,
- download the above files, or copy them:
cp ~cs50/public_html/Labs/Lab3/starter/hashtable/jhash.[ch] .
- extend
jhash.c
with a unit test like those we saw demonstrated in class today; you can#include "unittest.h"
and copy that file from~cs50/examples/unittest.h
for your testing.
unsigned long
JenkinsHash(const char *str, unsigned long mod)
{
if (str == NULL)
return 0;
size_t len = strlen(str);
unsigned long hash, i;
for (hash = i = 0; i < len; ++i)
{
hash += str[i];
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash % mod;
}