Skip to content

Commit e379583

Browse files
committed
unit test test_moving_average
1 parent f1a07bc commit e379583

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/test_plotting.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,21 @@ def test_extract_plot_data(data) -> None:
495495

496496
with pytest.raises(ValueError, match=r"Parameter `shift_value` must be between 0 and 100"):
497497
RATplot._extract_plot_data(data, False, True, 100.5)
498+
499+
500+
def test_moving_average() -> None:
501+
"""Test the moving_average function."""
502+
data_to_average = np.arange(0, 20)
503+
mov_avg = RATplot.moving_average(data_to_average)
504+
assert mov_avg == [1.5, 2.0, 2.5, 3.0, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.0,
505+
16.5, 17.0]
506+
507+
mov_avg = RATplot.moving_average(data_to_average, window_size=2)
508+
assert mov_avg == [0.0, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5,
509+
17.5, 18.5]
510+
511+
with pytest.raises(AssertionError):
512+
RATplot.moving_average(data_to_average, window_size=-1)
513+
514+
with pytest.raises(AssertionError):
515+
RATplot.moving_average(data_to_average, window_size=len(data_to_average)+1)

0 commit comments

Comments
 (0)