@@ -212,19 +212,91 @@ async def test_access_empty_window() -> None:
212212
213213async def test_window_size () -> None :
214214 """Test the size of the window."""
215- window , sender = init_moving_window (timedelta (seconds = 5 ))
215+ window , sender = init_moving_window (timedelta (seconds = 10 ))
216216 async with window :
217- assert window .capacity == 5 , "Wrong window capacity"
217+ assert window .capacity == 10 , "Wrong window capacity"
218218 assert window .count_valid () == 0 , "Window should be empty"
219219 assert window .count_covered () == 0 , "Window should be empty"
220+
220221 await push_logical_meter_data (sender , range (0 , 2 ))
221- assert window .capacity == 5 , "Wrong window capacity"
222+ assert window .capacity == 10 , "Wrong window capacity"
222223 assert window .count_valid () == 2 , "Window should be partially full"
223224 assert window .count_covered () == 2 , "Window should be partially full"
224- await push_logical_meter_data (sender , range (2 , 20 ))
225- assert window .capacity == 5 , "Wrong window capacity"
226- assert window .count_valid () == 5 , "Window should be full"
227- assert window .count_covered () == 5 , "Window should be full"
225+
226+ newest_ts = window .newest_timestamp
227+ assert newest_ts is not None and newest_ts == UNIX_EPOCH + timedelta (seconds = 1 )
228+
229+ await push_logical_meter_data (sender , range (2 , 5 ), start_ts = newest_ts )
230+ assert window .capacity == 10 , "Wrong window capacity"
231+ assert window .count_valid () == 4 , "Window should be partially full"
232+ assert window .count_covered () == 4 , "Window should be partially full"
233+
234+ newest_ts = window .newest_timestamp
235+ assert newest_ts is not None and newest_ts == UNIX_EPOCH + timedelta (seconds = 3 )
236+
237+ await push_logical_meter_data (sender , range (5 , 12 ), start_ts = newest_ts )
238+ assert window .capacity == 10 , "Wrong window capacity"
239+ assert window .count_valid () == 10 , "Window should be full"
240+ assert window .count_covered () == 10 , "Window should be full"
241+
242+ assert window .count_valid (since = UNIX_EPOCH + timedelta (seconds = 1 )) == 9
243+ assert window .count_valid (until = UNIX_EPOCH + timedelta (seconds = 2 )) == 3
244+ assert (
245+ window .count_valid (
246+ since = UNIX_EPOCH + timedelta (seconds = 1 ),
247+ until = UNIX_EPOCH + timedelta (seconds = 1 ),
248+ )
249+ == 1
250+ )
251+ assert (
252+ window .count_valid (
253+ since = UNIX_EPOCH + timedelta (seconds = 3 ),
254+ until = UNIX_EPOCH + timedelta (seconds = 8 ),
255+ )
256+ == 6
257+ )
258+ assert (
259+ window .count_valid (
260+ since = UNIX_EPOCH + timedelta (seconds = 8 ),
261+ until = UNIX_EPOCH + timedelta (seconds = 3 ),
262+ )
263+ == 0
264+ )
265+
266+ newest_ts = window .newest_timestamp
267+ assert newest_ts is not None and newest_ts == UNIX_EPOCH + timedelta (seconds = 9 )
268+ assert window .oldest_timestamp == UNIX_EPOCH
269+
270+ await push_logical_meter_data (sender , range (5 , 12 ), start_ts = newest_ts )
271+ assert window .capacity == 10 , "Wrong window capacity"
272+ assert window .count_valid () == 10 , "Window should be full"
273+ assert window .count_covered () == 10 , "Window should be full"
274+
275+ newest_ts = window .newest_timestamp
276+ assert newest_ts is not None and newest_ts == UNIX_EPOCH + timedelta (seconds = 15 )
277+ assert window .oldest_timestamp == UNIX_EPOCH + timedelta (seconds = 6 )
278+
279+ assert (
280+ window .count_valid (
281+ since = UNIX_EPOCH + timedelta (seconds = 1 ),
282+ until = UNIX_EPOCH + timedelta (seconds = 5 ),
283+ )
284+ == 0
285+ )
286+ assert (
287+ window .count_valid (
288+ since = UNIX_EPOCH + timedelta (seconds = 3 ),
289+ until = UNIX_EPOCH + timedelta (seconds = 8 ),
290+ )
291+ == 3
292+ )
293+ assert (
294+ window .count_valid (
295+ since = UNIX_EPOCH + timedelta (seconds = 6 ),
296+ until = UNIX_EPOCH + timedelta (seconds = 20 ),
297+ )
298+ == 10
299+ )
228300
229301
230302# pylint: disable=redefined-outer-name
0 commit comments