diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 87ef134..c532f5f 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,18 +1,58 @@ +import pytest + from pigeon_magnet_solver.helpers import (_fix_exes, _rotate_r, _valid_rotate, rotate_r) -def test_rotate_r(): - assert _rotate_r(list("1x01")) == list("11x0") - assert _rotate_r(list("11x0")) == list("011x") - assert _rotate_r(list("011x")) == list("x011") - assert _rotate_r(list("x011")) == list("1x01") +@pytest.mark.parametrize("test_input,expected", [ + # trivial cases + ("1111", "1111"), + ("0000", "0000"), + ("xxxx", "xxxx"), - assert _valid_rotate(list("1x01"), list("11x0")) is False - assert _valid_rotate(list("1x01"), list("011x")) is False - assert _valid_rotate(list("1x01"), list("x011")) is True - assert _valid_rotate(list("1x01"), list("1x01")) is True + # interesting case "1x01" + ("1x01", "11x0"), + ("11x0", "011x"), + ("011x", "x011"), + ("x011", "1x01"), +]) +def test__rotate_r(test_input: str, expected: str): + assert _rotate_r(list(test_input)) == list(expected) + +@pytest.mark.parametrize("test_input,candidate,expected", [ + # interesting case "1x01" + ("1x01", "11x0", False), + ("1x01", "011x", False), + ("1x01", "x011", True), + ("1x01", "1x01", True), +]) +def test__valid_rotate(test_input: str, candidate: str, expected: bool): + assert _valid_rotate(list(test_input), list(candidate)) is expected + + +def test__fix_exes(): assert _fix_exes(list("1x01"), list("x011")) == list("0x11") - assert rotate_r(list("1x01")) == list("0x11") + +@pytest.mark.parametrize("test_input,expected", [ + # trivial cases + ("1111", "1111"), + ("0000", "0000"), + ("xxxx", "xxxx"), + + # fixpoints "1x10" + ("1x10", "1x10"), + ("101x", "101x"), + ("1x1x", "1x1x"), + + # alternating case "1010" + ("1010", "0101"), + ("0101", "1010"), + + # interesting case "1x01" + ("1x01", "0x11"), + ("0x11", "1x01"), +]) +def test_rotate_r(test_input: str, expected: str): + assert rotate_r(list(test_input)) == list(expected)