Files
Technical-Assignment-CQG-Br…/tests/unit/test_sample_data.py
Martin Stajnko 40ea68be11 Initial implementation with unit and integration tests
Reads value1=value2 pairs from a configuration file and replaces every
non-overlapping occurrence of value1 with value2 in a text file, printing
the resulting lines sorted by the number of symbols replaced.

Overlapping patterns resolve to the longest match so the result does not
depend on configuration file ordering. Ties keep their original file order.
2026-08-25 21:21:38 +02:00

30 lines
921 B
Python

"""
Verifies the worked example from instructions.md line by line.
The end-to-end behaviour of that same example, including the sort order
and the printed output, is covered by tests/integration/test_cli.py.
"""
import pytest
from replacer import prepare_pairs, replace_line
SAMPLE_PAIRS = prepare_pairs([("a", "z"), ("bb", "y"), ("c", "x")])
# Each sample line mapped to its expected result and replacement count.
EXPECTED_RESULTS = {
"jgrebbk6hnae": ("jgreyk6hnze", 3),
"cnhjrfyjvth3nxr": ("xnhjrfyjvth3nxr", 1),
"b#sjcf_ansbbbbbvo!": ("b#sjxf_znsyybvo!", 6),
"dajf#aemfaocfna%": ("dzjf#zemfzoxfnz%", 5),
}
@pytest.mark.parametrize("line", list(EXPECTED_RESULTS))
def test_each_sample_line(line):
expected_result, expected_replaced = EXPECTED_RESULTS[line]
result, replaced = replace_line(line, SAMPLE_PAIRS)
assert result == expected_result
assert replaced == expected_replaced