from snapshot_sequence import MAX_SEQUENCE, SequenceCounter, SequenceWindow, is_newer, next_sequence def test_next_sequence_skips_zero_after_wrap(): assert next_sequence(0) == 1 assert next_sequence(1) == 2 assert next_sequence(MAX_SEQUENCE) == 1 def test_is_newer_is_wrap_safe(): assert is_newer(1, 0) assert is_newer(2, 1) assert not is_newer(1, 1) assert not is_newer(1, 2) assert is_newer(1, MAX_SEQUENCE) assert not is_newer(MAX_SEQUENCE, 1) assert not is_newer(0, MAX_SEQUENCE) def test_counter_and_window_enforce_latest_wins(): counter = SequenceCounter() assert counter.current == 0 assert counter.advance() == 1 assert counter.advance() == 2 counter.reset() assert counter.advance() == 1 window = SequenceWindow() assert window.accept(1) assert not window.accept(1) assert window.accept(2) assert not window.accept(1) window.reset() assert window.accept(MAX_SEQUENCE) assert window.accept(1) assert not window.accept(MAX_SEQUENCE) def test_invalid_sequence_inputs_are_rejected(): assert not is_newer(-1, 0) assert not is_newer(1, -1) assert not is_newer(True, 0) assert not is_newer(1, MAX_SEQUENCE + 1)