Fix boundary check and add unit tests

* Fix not purging entries when their time is exactly one period earlier

* Several new unit tests to cover the above bug

* Several new interface functions with the main focus being on testing

* now is based on the request time, not the current time (this might
  result in entries being out of order, but it should be okay...?)