def test_get_int(self): input_seq = ["as", "one", "3.14", "r112", " 34 "] with mock.patch("builtins.input", side_effect=input_seq): self.assertEqual(ioutil.get_int(""), 34) input_seq = ["\n42 \t"] with mock.patch("builtins.input", side_effect=input_seq): self.assertEqual(ioutil.get_int(""), 42)
def test_get_int(self): input_seq = ['as', 'one', '3.14', 'r112', ' 34 '] with mock.patch('builtins.input', side_effect=input_seq): self.assertEqual(ioutil.get_int(''), 34) input_seq = ['\n42 \t'] with mock.patch('builtins.input', side_effect=input_seq): self.assertEqual(ioutil.get_int(''), 42)
def play_round(self): """Plays one round of a game. A round start with an empty board and players make their moves in turn, until one is victorious or the board is filled. """ self.board = board.Board(self.width, self.height, self.players, self.size) self.round_counter += 1 while True: print('Currently on turn: {}.'.format(self.players[self.on_turn])) print(self.board) while True: position = ioutil.get_int('Please input a position: ') try: self.board.set(position, self.on_turn) break except ValueError: print('Position {} invalid.'.format(position)) outcome, winner = self.board.finished() if outcome: print(self.board) if winner is None: print("It's a tie!") else: print("Player {} won!".format(self.players[winner])) self.players[winner].won += 1 for j in range(len(self.players)): print("Player {0} won {1} game{2}!".format(self.players[j], self.players[j].won, 's' if self.players[j].won != 1 else '')) break self.on_turn += 1 self.on_turn %= self.num_of_players