Skip to content

Commit

Permalink
Enhance index access tests for moving window
Browse files Browse the repository at this point in the history
  • Loading branch information
cwasicki committed Sep 14, 2023
1 parent 26590c0 commit f3d5e1b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/timeseries/test_moving_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ def dt(i: int) -> datetime: # pylint: disable=invalid-name

async def test_access_window_by_index() -> None:
"""Test indexing a window by integer index."""
window, sender = init_moving_window(timedelta(seconds=1))
window, sender = init_moving_window(timedelta(seconds=2))
async with window:
await push_logical_meter_data(sender, [1])
assert np.array_equal(window[0], 1.0)
await push_logical_meter_data(sender, [1, 2, 3])
assert np.array_equal(window[0], 3.0) # bug: should be 2
assert np.array_equal(window[1], 2.0) # bug: should be 3
assert np.array_equal(window[-1], 2.0) # bug: should be 3
assert np.array_equal(window[-2], 3.0) # bug: should be 2
with pytest.raises(IndexError):
_ = window[3]
with pytest.raises(IndexError):
_ = window[-3]


async def test_access_window_by_timestamp() -> None:
Expand Down

0 comments on commit f3d5e1b

Please sign in to comment.