Refactor test functions to use function objects