2023-08-22 22:00:44 +00:00
|
|
|
import pytest
|
|
|
|
|
2023-08-20 11:41:07 +00:00
|
|
|
from pigeon_magnet_solver.helpers import (_fix_exes, _rotate_r, _valid_rotate,
|
|
|
|
rotate_r)
|
2023-08-18 22:34:02 +00:00
|
|
|
|
|
|
|
|
2023-08-22 22:00:44 +00:00
|
|
|
@pytest.mark.parametrize("test_input,expected", [
|
|
|
|
# trivial cases
|
|
|
|
("1111", "1111"),
|
|
|
|
("0000", "0000"),
|
|
|
|
("xxxx", "xxxx"),
|
|
|
|
|
|
|
|
# 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
|
2023-08-18 22:34:02 +00:00
|
|
|
|
|
|
|
|
2023-08-22 22:00:44 +00:00
|
|
|
def test__fix_exes():
|
2023-08-20 11:41:07 +00:00
|
|
|
assert _fix_exes(list("1x01"), list("x011")) == list("0x11")
|
2023-08-18 22:34:02 +00:00
|
|
|
|
2023-08-22 22:00:44 +00:00
|
|
|
|
|
|
|
@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)
|