def test_moving_average__empty(): #It should be possible to initialize with an empty list ts = TimeSeries([]) ts.moving_average(3) assert(ts.data==[])
def test_moving_average__first_val(): ts = TimeSeries(sample_data) original_len = len(ts.data) ts.moving_average(3) assert(ts.data[0][-1]==(200+50)/3)
def test_moving_average__first_day(window): ts = TimeSeries(sample_data) ts.moving_average(window) assert(ts.data[0][0]==sample_data[0][0]+datetime.timedelta(window-1))
def test_moving_average__last_day(window): ts = TimeSeries(sample_data) original_len = len(ts.data) ts.moving_average(window) assert(ts.data[-1][0]==sample_data[-1][0])
def test_moving_average__len(window): ts = TimeSeries(sample_data) original_len = len(ts.data) ts.moving_average(window) assert(len(ts.data)==original_len-window+1)