Add unit tests for metrics support functions

I was bad and didn't write tests for all the functions that are used for generating metrics. I noticed a bug, which this fixes as well as adding tests for all the support functions. I still need to write a bunch of tests for the `update_metrics` function itself, but this is a start.