Ejemplo n.º 1
0
class TestTTTGameRunner(unittest.TestCase):
  def setUp(self):
    self.runner = TTTGameRunner()
    self.runner.io = TestIO()
    self.runner.ai = TestAI()
  
  def test_asks_for_valid_team_until_one_is_provided(self):
    team = self.runner._get_valid_human_team()
    self.assertEqual(1, self.runner.io.it_called_count)
    self.assertEqual('X', team)
  
  def test_asks_for_valid_move_until_one_is_provided(self):
    self.runner._make_valid_move()
    self.assertEqual(1, self.runner.io.im_called_count)
    self.assertEqual('X', self.runner.board.space_contents(1))
  
  def test_human_and_computer_players_alternate_turns(self):
    self.runner.human_team = 'X'
    self.runner._take_turn('X')
    self.runner._take_turn('O')
    self.assertEqual(2, self.runner.board.num_full_spaces())
    self.assertEqual('X', self.runner.board.space_contents(1))
    self.assertEqual('O', self.runner.board.space_contents(3))
  
  def test_plays_a_game_until_it_is_done(self):
    self.runner.run_game()
    self.assertEqual(5, self.runner.board.num_full_spaces())
    self.assertEqual(1, self.runner.io.sw_called_count)
  
  def test_shows_winner(self):
    self.runner.rules.get_winner = lambda board: 'X'
    self.runner.game_over()
    self.assertEqual(1, self.runner.io.sw_called_count)
    
  def test_shows_tie_game(self):
    self.runner.rules.get_winner = lambda board: None
    self.runner.game_over()
    self.assertEqual(1, self.runner.io.tg_called_count)
Ejemplo n.º 2
0
from src.ttt_game_runner import TTTGameRunner
runner = TTTGameRunner()
runner.run_game()

# Note to self: Play game from command line with 'python3 ./play_ttt.py'