mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 23:00:43 -08:00
Acey Ducey (Python): Add unit tests
The unit tests can be executed via:
$ pip install pytest
$ pytest .
Also a few more type annotations
This commit is contained in:
19
01_Acey_Ducey/python/test_acey_ducey.py
Normal file
19
01_Acey_Ducey/python/test_acey_ducey.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import io
|
||||
from unittest import mock
|
||||
|
||||
from acey_ducey import play_game
|
||||
|
||||
|
||||
@mock.patch("random.shuffle")
|
||||
def test_play_game_lose(mock_random_shuffle, monkeypatch, capsys) -> None:
|
||||
monkeypatch.setattr("sys.stdin", io.StringIO("100\n100"))
|
||||
mock_random_shuffle = lambda n: n
|
||||
play_game()
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == (
|
||||
"You now have 100 dollars\n\n"
|
||||
"Here are you next two cards\n King\n Ace\n\n"
|
||||
"What is your bet? Queen\n"
|
||||
"Sorry, you lose\n"
|
||||
"Sorry, friend, but you blew your wad\n"
|
||||
)
|
||||
Reference in New Issue
Block a user