(capsys)
| 10 | assert towerofhanoi.COMPLETE_TOWER == [5, 4, 3, 2, 1] |
| 11 | |
| 12 | def test_getPlayerMove(capsys): |
| 13 | towers = {'A': copy.copy(towerofhanoi.COMPLETE_TOWER), 'B': [], 'C': []} |
| 14 | |
| 15 | sys.stdin = io.StringIO('AB\n') |
| 16 | assert towerofhanoi.getPlayerMove(towers) == ('A', 'B') |
| 17 | |
| 18 | sys.stdin = io.StringIO(' ab \n') |
| 19 | assert towerofhanoi.getPlayerMove(towers) == ('A', 'B') |
| 20 | |
| 21 | # Test entering an invalid move: |
| 22 | sys.stdin = io.StringIO('invalid\nquit\n') |
| 23 | with pytest.raises(SystemExit): |
| 24 | towerofhanoi.getPlayerMove(towers) |
| 25 | captured = capsys.readouterr() |
| 26 | assert 'Enter one of AB, AC, BA, BC, CA, or CB.' in captured.out |
| 27 | |
| 28 | # Test quitting: |
| 29 | with pytest.raises(SystemExit): |
| 30 | sys.stdin = io.StringIO('QUIT\n') |
| 31 | towerofhanoi.getPlayerMove(towers) |
| 32 | |
| 33 | with pytest.raises(SystemExit): |
| 34 | sys.stdin = io.StringIO('quit\n') |
| 35 | towerofhanoi.getPlayerMove(towers) |
| 36 | |
| 37 | with pytest.raises(SystemExit): |
| 38 | sys.stdin = io.StringIO('qUiT\n') |
| 39 | towerofhanoi.getPlayerMove(towers) |
| 40 | |
| 41 | with pytest.raises(SystemExit): |
| 42 | sys.stdin = io.StringIO(' quit \n') |
| 43 | towerofhanoi.getPlayerMove(towers) |
| 44 | |
| 45 | # Test selecting an empty tower: |
| 46 | sys.stdin = io.StringIO('ba\nquit\n') |
| 47 | with pytest.raises(SystemExit): |
| 48 | towerofhanoi.getPlayerMove(towers) |
| 49 | captured = capsys.readouterr() |
| 50 | assert 'You selected a tower with no disks.' in captured.out |
| 51 | |
| 52 | # Test trying to put a disk on a smaller disk: |
| 53 | towers = {'A': [5, 4, 3, 2], 'B': [1], 'C': []} |
| 54 | sys.stdin = io.StringIO('ab\nquit\n') |
| 55 | with pytest.raises(SystemExit): |
| 56 | towerofhanoi.getPlayerMove(towers) |
| 57 | captured = capsys.readouterr() |
| 58 | assert 'Can\'t put larger disks on top of smaller ones.' in captured.out |
| 59 | |
| 60 | |
| 61 | def test_main(capsys): |
nothing calls this directly
no outgoing calls
no test coverage detected