The project has a small component for previewing and counting events from a string source. After a recent change, the behavior started to diverge from the requirements.
You need to review the diff and find defects in the modified code.
Functional requirements:
EventDigest.preview(source, limit) returns no more than limit non-empty strings after strip() in the original order.EventDigest.count(source) counts the number of non-empty strings after strip().source may be any Iterable[str], including a one-shot generator.preview(source, limit) must not change the result of a subsequent count(source) for the same source if the caller passes the same object.EventDigest instances must not share accumulated state.Environment and run:
python -m unittest -q.strip() returns "" are considered empty.You need to describe what problems exist in the after version, why they are reproducible, and how to fix them.
CPython 3.12, standard library only, run tests via python -m unittest -q from the project root.
Use line comments to explain the problem, its impact, the fix and how to test it.