Amazing (Python): Code Cleanup

* Make more use of a Maze class
* Create a bigger maze in the test
* Group row/col variables in Position class
* Group direction variables in an Enum
This commit is contained in:
Martin Thoma
2022-03-21 14:30:14 +01:00
parent 373e5a1868
commit 49ae4f4872
2 changed files with 171 additions and 94 deletions
+33 -2
View File
@@ -1,8 +1,13 @@
import io
import pytest
from amazing import build_maze, welcome_header
from _pytest.capture import CaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from amazing import build_maze, welcome_header, main
def test_welcome_header(capsys) -> None:
def test_welcome_header(capsys: CaptureFixture[str]) -> None:
capsys.readouterr()
welcome_header()
out, err = capsys.readouterr()
assert out == (
@@ -25,3 +30,29 @@ def test_welcome_header(capsys) -> None:
def test_build_maze(width: int, length: int) -> None:
with pytest.raises(AssertionError):
build_maze(width, length)
@pytest.mark.parametrize(
("width", "length"),
[
(3, 3),
(10, 10),
],
)
def test_main(monkeypatch: MonkeyPatch, width: int, length: int) -> None:
monkeypatch.setattr(
"sys.stdin",
io.StringIO(f"{width},{length}"),
)
main()
def test_main_error(monkeypatch: MonkeyPatch) -> None:
width = 1
length = 2
monkeypatch.setattr(
"sys.stdin",
io.StringIO(f"{width},{length}\n3,3"),
)
main()