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 /thayerfs/courses/22spring/cosc050/workspace/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 /thayerfs/courses/22spring/cosc050/workspace/unittest.h for your testing.
unsigned long
JenkinsHash(const char *str, const unsigned long mod)
{
  if (str == NULL) {
    return 0;
  }

  size_t len = strlen(str);
  unsigned long hash = 0;

  for (int 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);
}