Add a test case for rolling averages and fix two bugs that it uncovered