MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / test_randomMoves

Function test_randomMoves

tests/test_towerofhanoi.py:147–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145
146
147def test_randomMoves():
148 towers = {'A': copy.copy(towerofhanoi.COMPLETE_TOWER), 'B': [], 'C': []}
149
150 random.seed(42)
151 for i in range(10000):
152 randomMove = random.choice(('AB', 'AC', 'BA', 'BC', 'CA', 'CB'))
153 sys.stdin = io.StringIO(randomMove + '\nQUIT\n')
154 try:
155 move = towerofhanoi.getPlayerMove(towers)
156 except SystemExit:
157 continue
158
159 # (Copy/pasted from main())
160 # Ask the user for a move:
161 fromTower, toTower = move
162
163 # Move the top disk from fromTower to toTower:
164 disk = towers[fromTower].pop()
165 towers[toTower].append(disk)
166
167 isValidTowerConfiguration(towers)

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected