def test_current_range_is_latest_range(self): size = 57 step = 23 timestamp = 456 window = SlidingWindow(size, step, expires=30) ranges = window.ranges(timestamp) current_range = window.current(timestamp) assert current_range == ranges[-1]
def test_earliest_range_is_first_range(self): size = 100 step = 15 timestamp = 3223 window = SlidingWindow(size, step, expires=30) ranges = window.ranges(timestamp) earliest_range = window.earliest(timestamp) assert earliest_range == ranges[0]
def test_has_ranges_including_the_value(self): size = 10 step = 5 timestamp = 6 window = SlidingWindow(size, step, expires=30) window_ranges = window.ranges(timestamp) assert len(window_ranges) == 1 for range in window_ranges: assert range[0] <= timestamp assert range[1] > timestamp