diff --git a/crm_5_implementation.py b/crm_5_implementation.py
index 11b9333..521ad95 100644
--- a/crm_5_implementation.py
+++ b/crm_5_implementation.py
@@ -1,195 +1,279 @@
-"""
-Tic Tac Toe Game Implementation (Clean Version)
-
-Python backend game engine with optional HTML/CSS/JS generation.
-"""
-
-from typing import List, Optional, Dict, Any
-import json
-
-
-# -----------------------------
-# Player
-# -----------------------------
-class Player:
- """Represents a Tic Tac Toe player."""
-
- def __init__(self, symbol: str, name: str):
- if symbol not in ("X", "O"):
- raise ValueError("Symbol must be 'X' or 'O'")
- self.symbol = symbol
- self.name = name
-
-
-# -----------------------------
-# Game Board
-# -----------------------------
-class GameBoard:
- """3x3 Tic Tac Toe board."""
-
- def __init__(self):
- self.size = 3
- self.board = [["" for _ in range(3)] for _ in range(3)]
-
- def get_cell(self, row: int, col: int) -> str:
- self._validate_position(row, col)
- return self.board[row][col]
-
- def set_cell(self, row: int, col: int, symbol: str) -> None:
- self._validate_position(row, col)
-
- if symbol not in ("X", "O"):
- raise ValueError("Invalid symbol")
-
- if self.board[row][col] != "":
- raise ValueError("Cell already occupied")
-
- self.board[row][col] = symbol
-
- def clear_cell(self, row: int, col: int) -> None:
- self._validate_position(row, col)
- self.board[row][col] = ""
-
- def is_full(self) -> bool:
- return all(cell != "" for row in self.board for cell in row)
-
- def reset(self) -> None:
- self.board = [["" for _ in range(3)] for _ in range(3)]
-
- def to_dict(self) -> List[List[str]]:
- return [row[:] for row in self.board]
-
- def _validate_position(self, row: int, col: int) -> None:
- if not (0 <= row < 3 and 0 <= col < 3):
- raise IndexError("Row and column must be between 0 and 2")
-
-
-# -----------------------------
-# Win Checker
-# -----------------------------
-class WinChecker:
- """Utility class for win checking."""
-
- @staticmethod
- def check_winner(board: GameBoard) -> Optional[str]:
- b = board.board
-
- lines = (
- # rows
- b[0], b[1], b[2],
- # columns
- [b[0][0], b[1][0], b[2][0]],
- [b[0][1], b[1][1], b[2][1]],
- [b[0][2], b[1][2], b[2][2]],
- # diagonals
- [b[0][0], b[1][1], b[2][2]],
- [b[0][2], b[1][1], b[2][0]],
- )
-
- for line in lines:
- if line[0] and line.count(line[0]) == 3:
- return line[0]
-
- return None
-
-
-# -----------------------------
-# Game Engine
-# -----------------------------
-class GameEngine:
- """Main Tic Tac Toe game engine."""
-
- def __init__(self):
- self.players = [
- Player("X", "Player X"),
- Player("O", "Player O"),
- ]
- self.current_player_index = 0
- self.board = GameBoard()
- self.winner: Optional[str] = None
- self.game_over = False
- self.move_history: List[Dict[str, Any]] = []
-
- def current_player(self) -> Player:
- return self.players[self.current_player_index]
-
- def make_move(self, row: int, col: int) -> Dict[str, Any]:
- if self.game_over:
- return {"success": False, "error": "Game is already over"}
-
- try:
- symbol = self.current_player().symbol
- self.board.set_cell(row, col, symbol)
+import logging
+from flask import Flask, render_template_string
+from typing import Final
+
+# Configure logging for production monitoring
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+
+# Constants for Server Configuration
+HOST: Final[str] = "0.0.0.0"
+PORT: Final[int] = 5000
+DEBUG: Final[bool] = False
+
+# HTML/CSS/JS Template implementing the requested Architecture Design
+# This includes the Game Board, Status Indicator, and Game Logic Engine
+TIC_TAC_TOE_TEMPLATE: Final[str] = """
+
+
+
+
+
+ Production Tic Tac Toe
+
+
+
+
+
+
Tic Tac Toe
+
Player X's Turn
+
+
+
+
+
+
+
+
+
+"""
+class TicTacToeApp:
+ """
+ Production-ready Flask Application wrapper for Tic Tac Toe.
+ Encapsulates server logic and template rendering.
+ """
+
+ def __init__(self, name: str = __name__):
+ """
+ Initializes the Flask application and defines routes.
+
+ :param name: The name of the application module.
+ """
+ self.app = Flask(name)
+ self._setup_routes()
+
+ def _setup_routes(self) -> None:
+ """
+ Defines the routing table for the web application.
+ """
+ @self.app.route('/')
+ def index() -> str:
+ """
+ Serves the main Tic Tac Toe game page.
+
+ :return: Rendered HTML string.
+ """
+ try:
+ return render_template_string(TIC_TAC_TOE_TEMPLATE)
+ except Exception as e:
+ logger.error(f"Error rendering template: {e}")
+ return "Internal Server Error", 500
+
+ def run(self, host: str = HOST, port: int = PORT, debug: bool = DEBUG) -> None:
+ """
+ Starts the Flask development server.
+
+ :param host: Network address to bind to.
+ :param port: Port to listen on.
+ :param debug: Enable/disable debug mode.
+ """
+ try:
+ logger.info(f"Starting Tic Tac Toe server on {host}:{port}")
+ self.app.run(host=host, port=port, debug=debug)
+ except Exception as e:
+ logger.critical(f"Server failed to start: {e}")
if __name__ == "__main__":
- main()
+ # Instantiate and run the production-ready game server
+ game_server = TicTacToeApp()
+ game_server.run()
\ No newline at end of file
diff --git a/test_crm_5_implementation.py b/test_crm_5_implementation.py
index 5106b70..1e46054 100644
--- a/test_crm_5_implementation.py
+++ b/test_crm_5_implementation.py
@@ -1,289 +1,135 @@
-"""
-Comprehensive unit tests for Tic Tac Toe game implementation.
-
-Tests all classes, methods, and edge cases for the Tic Tac Toe game.
-"""
-
import pytest
-from crm_5_implementation import TicTacToeGame, TicTacToeUI, create_tic_tac_toe_game
-
-
-class TestTicTacToeGame:
- """Test cases for the TicTacToeGame class."""
-
- def test_initialization(self):
- """Test that game initializes correctly."""
- game = TicTacToeGame()
- assert game.board == [''] * 9
- assert game.current_player == 'X'
- assert game.game_over is False
- assert game.winner is None
- assert game.move_count == 0
-
- def test_make_move_valid_position(self):
- """Test making a valid move at position 0."""
- game = TicTacToeGame()
- result = game.make_move(0)
- assert result is True
- assert game.board[0] == 'X'
- assert game.current_player == 'O'
- assert game.move_count == 1
-
- def test_make_move_invalid_position_negative(self):
- """Test making a move at negative position."""
- game = TicTacToeGame()
- with pytest.raises(ValueError):
- game.make_move(-1)
-
- def test_make_move_invalid_position_too_high(self):
- """Test making a move at position 9."""
- game = TicTacToeGame()
- with pytest.raises(ValueError):
- game.make_move(9)
-
- def test_make_move_occupied_position(self):
- """Test making a move at already occupied position."""
- game = TicTacToeGame()
- game.make_move(0) # X at position 0
- with pytest.raises(IndexError):
- game.make_move(0) # Try to place O at same position
-
- def test_make_move_game_over(self):
- """Test making a move after game is already over."""
- game = TicTacToeGame()
- # Fill the board to make it full
- for i in range(9):
- game.make_move(i)
- # Try to make another move
- result = game.make_move(8)
- assert result is False
-
- def test_check_win_rows(self):
- """Test win detection for rows."""
- game = TicTacToeGame()
- # X wins with first row
- game.make_move(0)
- game.make_move(3)
- game.make_move(1)
- game.make_move(4)
- result = game.make_move(2)
- assert result is True
- assert game.game_over is True
- assert game.winner == 'X'
-
- def test_check_win_columns(self):
- """Test win detection for columns."""
- game = TicTacToeGame()
- # O wins with first column
- game.make_move(0)
- game.make_move(3)
- game.make_move(1)
- game.make_move(6)
- result = game.make_move(2)
- assert result is True
- assert game.game_over is True
- assert game.winner == 'X'
-
- def test_check_win_diagonals(self):
- """Test win detection for diagonals."""
- game = TicTacToeGame()
- # X wins with diagonal
- game.make_move(0)
- game.make_move(1)
- game.make_move(4)
- game.make_move(2)
- result = game.make_move(8)
- assert result is True
- assert game.game_over is True
- assert game.winner == 'X'
-
- def test_check_win_draw(self):
- """Test draw detection."""
- game = TicTacToeGame()
- # Fill board with alternating moves to create a draw
- game.make_move(0) # X
- game.make_move(1) # O
- game.make_move(2) # X
- game.make_move(4) # O
- game.make_move(3) # X
- game.make_move(5) # O
- game.make_move(7) # X
- game.make_move(6) # O
- result = game.make_move(8) # X - should end in draw
- assert result is True
- assert game.game_over is True
- assert game.winner == 'Draw'
-
- def test_reset_game(self):
- """Test resetting the game."""
- game = TicTacToeGame()
- game.make_move(0)
- game.make_move(1)
- game.reset_game()
- assert game.board == [''] * 9
- assert game.current_player == 'X'
- assert game.game_over is False
- assert game.winner is None
- assert game.move_count == 0
-
- def test_get_board_state(self):
- """Test getting board state."""
- game = TicTacToeGame()
- game.make_move(0)
- board_state = game.get_board_state()
- assert board_state[0] == 'X'
- assert board_state[1] == ''
- # Original board should be unchanged
- assert game.board[0] == 'X'
-
- def test_get_game_status(self):
- """Test getting game status."""
- game = TicTacToeGame()
- game.make_move(0)
- status = game.get_game_status()
- assert status['board'][0] == 'X'
- assert status['current_player'] == 'O'
- assert status['game_over'] is False
- assert status['winner'] is None
- assert status['move_count'] == 1
-
- def test_alternating_players(self):
- """Test that players alternate correctly."""
- game = TicTacToeGame()
- game.make_move(0)
- assert game.current_player == 'O'
- game.make_move(1)
- assert game.current_player == 'X'
- game.make_move(2)
- assert game.current_player == 'O'
-
-
-class TestTicTacToeUI:
- """Test cases for the TicTacToeUI class."""
-
- def test_ui_initialization(self):
- """Test UI initialization."""
- ui = TicTacToeUI()
- assert isinstance(ui.game, TicTacToeGame)
-
- def test_generate_html(self):
- """Test HTML generation."""
- ui = TicTacToeUI()
- html_content = ui.generate_html()
- assert '' in html_content
- assert 'Tic Tac Toe' in html_content
- assert '' in html_content
-
- def test_generate_css(self):
- """Test CSS generation."""
- ui = TicTacToeUI()
- css_content = ui.generate_css()
- assert 'body {' in css_content
- assert '.cell {' in css_content
- assert '@media' in css_content
-
- def test_generate_javascript(self):
- """Test JavaScript generation."""
- ui = TicTacToeUI()
- js_content = ui.generate_javascript()
- assert 'class TicTacToeGame' in js_content
- assert 'makeMove' in js_content
- assert 'updateUI' in js_content
-
-
-def test_create_tic_tac_toe_game():
- """Test creating complete game package."""
- result = create_tic_tac_toe_game()
- assert isinstance(result, dict)
- assert 'html' in result
- assert 'css' in result
- assert 'js' in result
- assert len(result['html']) > 0
- assert len(result['css']) > 0
- assert len(result['js']) > 0
-
-
-def test_main_function():
- """Test main function runs without errors."""
- # This is mainly for code coverage and to ensure the function can run
- # The actual content is tested in other tests
- pass
-
-
-class TestEdgeCases:
- """Test edge cases for the game."""
-
- def test_multiple_wins_same_row(self):
- """Test that win is detected correctly even with multiple moves."""
- game = TicTacToeGame()
- # Create a winning condition
- game.make_move(0) # X
- game.make_move(3) # O
- game.make_move(1) # X
- game.make_move(4) # O
- result = game.make_move(2) # X - should win
- assert result is True
- assert game.game_over is True
- assert game.winner == 'X'
-
- def test_full_board_draw(self):
- """Test draw with specific board arrangement."""
- game = TicTacToeGame()
- # Create a full board that should end in draw
- moves = [0, 1, 2, 4, 3, 5, 7, 6, 8] # X, O, X, O, X, O, X, O, X
- for i, move in enumerate(moves):
- game.make_move(move)
- assert game.game_over is True
- assert game.winner == 'Draw'
-
- def test_empty_board(self):
- """Test that initial board is empty."""
- game = TicTacToeGame()
- assert all(cell == '' for cell in game.board)
-
- def test_invalid_move_after_win(self):
- """Test making move after win."""
- game = TicTacToeGame()
- # Create a win condition
- game.make_move(0) # X
- game.make_move(3) # O
- game.make_move(1) # X
- game.make_move(4) # O
- game.make_move(2) # X - win
- # Try to make another move after win
- result = game.make_move(5)
- assert result is False
-
- def test_multiple_resets(self):
- """Test resetting multiple times."""
- game = TicTacToeGame()
- game.make_move(0)
- game.reset_game()
- game.reset_game() # Second reset
- assert game.board == [''] * 9
- assert game.current_player == 'X'
-
- def test_win_with_different_patterns(self):
- """Test win detection with different patterns."""
- game = TicTacToeGame()
-
- # Test column win
- game.make_move(0) # X
- game.make_move(1) # O
- game.make_move(3) # X
- game.make_move(4) # O
- result = game.make_move(6) # X - win column 0
- assert result is True
- assert game.game_over is True
- assert game.winner == 'X'
+from unittest.mock import patch, MagicMock
+from flask import Flask
+from crm_5_implementation import TicTacToeApp, HOST, PORT, DEBUG, TIC_TAC_TOE_TEMPLATE
+
+@pytest.fixture
+def app_instance():
+ """Fixture to provide a fresh instance of TicTacToeApp for each test."""
+ return TicTacToeApp()
+
+@pytest.fixture
+def client(app_instance):
+ """Fixture to provide a Flask test client."""
+ app_instance.app.config['TESTING'] = True
+ return app_instance.app.test_client()
+
+def test_app_initialization(app_instance):
+ """
+ Test that the TicTacToeApp initializes correctly.
+ Verifies that the Flask app object is created and routes are set.
+ """
+ assert isinstance(app_instance.app, Flask)
+ assert app_instance.app.name == "crm_5_implementation"
+
+def test_index_route_success(client):
+ """
+ Positive test case for the index route.
+ Verifies that the root URL returns a 200 OK status and contains expected HTML content.
+ """
+ response = client.get('/')
+ assert response.status_code == 200
+ assert "Tic Tac Toe" in response.get_data(as_text=True)
+ assert "GameEngine" in response.get_data(as_text=True)
+ assert "UIController" in response.get_data(as_text=True)
+
+def test_index_route_template_error(app_instance):
+ """
+ Negative test case for the index route.
+ Mocks render_template_string to raise an exception and verifies 500 error handling.
+ """
+ with patch('crm_5_implementation.render_template_string') as mocked_render:
+ mocked_render.side_effect = Exception("Template rendering failed")
- # Reset and test diagonal win
- game.reset_game()
- game.make_move(0) # X
- game.make_move(1) # O
- game.make_move(4) # X
- game.make_move(2) # O
- result = game.make_move(8) # X - win diagonal
- assert result is True
- assert game.game_over is True
- assert game.winner == 'X'
\ No newline at end of file
+ # We need to use the app's test client
+ with app_instance.app.test_client() as client:
+ response = client.get('/')
+ assert response.status_code == 500
+ assert b"Internal Server Error" in response.data
+
+def test_run_method_success(app_instance):
+ """
+ Positive test case for the run method.
+ Verifies that the Flask run method is called with the correct parameters.
+ """
+ with patch.object(app_instance.app, 'run') as mocked_run:
+ app_instance.run(host="127.0.0.1", port=8080, debug=True)
+ mocked_run.assert_called_once_with(host="127.0.0.1", port=8080, debug=True)
+
+def test_run_method_default_parameters(app_instance):
+ """
+ Test the run method with default configuration constants.
+ """
+ with patch.object(app_instance.app, 'run') as mocked_run:
+ app_instance.run()
+ mocked_run.assert_called_once_with(host=HOST, port=PORT, debug=DEBUG)
+
+def test_run_method_failure(app_instance):
+ """
+ Edge case: Test the run method when the server fails to start.
+ Verifies that the critical error is logged.
+ """
+ with patch.object(app_instance.app, 'run', side_effect=RuntimeError("Port in use")):
+ with patch('crm_5_implementation.logger.critical') as mocked_log:
+ app_instance.run()
+ mocked_log.assert_called_once()
+ assert "Server failed to start" in mocked_log.call_args[0][0]
+
+def test_constants_values():
+ """
+ Verify that the configuration constants are set to expected production values.
+ """
+ assert HOST == "0.0.0.0"
+ assert PORT == 5000
+ assert DEBUG is False
+
+def test_template_content_integrity():
+ """
+ Verify that the HTML template contains essential UI components.
+ """
+ assert 'id="board"' in TIC_TAC_TOE_TEMPLATE
+ assert 'id="status"' in TIC_TAC_TOE_TEMPLATE
+ assert 'id="reset"' in TIC_TAC_TOE_TEMPLATE
+ assert 'class="cell"' in TIC_TAC_TOE_TEMPLATE
+
+def test_logger_configuration():
+ """
+ Verify that the logger is correctly named.
+ """
+ from crm_5_implementation import logger
+ assert logger.name == "crm_5_implementation"
+
+@pytest.mark.parametrize("path", ["/invalid", "/game", "/api"])
+def test_invalid_routes(client, path):
+ """
+ Negative test case: Verify that undefined routes return 404.
+ """
+ response = client.get(path)
+ assert response.status_code == 404
+
+def test_index_route_logging(app_instance):
+ """
+ Test that errors during rendering are logged.
+ """
+ with patch('crm_5_implementation.render_template_string', side_effect=Exception("Log Test")):
+ with patch('crm_5_implementation.logger.error') as mocked_error_log:
+ with app_instance.app.test_client() as client:
+ client.get('/')
+ mocked_error_log.assert_called_once()
+ assert "Error rendering template" in mocked_error_log.call_args[0][0]
+
+def test_app_setup_routes_called(app_instance):
+ """
+ Verify that _setup_routes is called during initialization.
+ """
+ with patch.object(TicTacToeApp, '_setup_routes') as mocked_setup:
+ # Re-instantiate to trigger the constructor
+ TicTacToeApp()
+ mocked_setup.assert_called_once()
+
+def test_flask_app_config(app_instance):
+ """
+ Verify Flask internal configuration.
+ """
+ assert app_instance.app.static_folder is None # Default when not specified in this setup
+ assert app_instance.app.template_folder == 'templates' # Flask default
\ No newline at end of file
diff --git a/test_integration.py b/test_integration.py
index 4f05c43..1df776c 100644
--- a/test_integration.py
+++ b/test_integration.py
@@ -1,330 +1,83 @@
-"""
-Integration tests for Tic Tac Toe Game Implementation
-
-This module contains integration tests that verify the complete
-Tic Tac Toe game functionality including HTML, CSS, and JavaScript
-components working together.
-"""
-
import pytest
-from unittest.mock import patch, MagicMock
-from crm_5_implementation import TicTacToeGame
-import json
-
-
-@pytest.fixture(scope="module")
-def game_instance():
- """
- Fixture to create a Tic Tac Toe game instance for testing.
-
- Returns:
- TicTacToeGame: An instance of the Tic Tac Toe game class
- """
- return TicTacToeGame()
-
-
-@pytest.fixture(scope="function")
-def setup_game_state(game_instance):
- """
- Fixture to set up a clean game state before each test.
-
- Args:
- game_instance: The Tic Tac Toe game instance
-
- Returns:
- TicTacToeGame: Game instance with reset state
- """
- game_instance.reset_game()
- return game_instance
-
-
-def test_game_initialization(setup_game_state):
- """
- Test that the Tic Tac Toe game initializes correctly.
-
- This test verifies that the game starts with the correct initial state
- including an empty board, proper player turns, and valid game status.
- """
- game = setup_game_state
-
- # Verify initial board state
- expected_board = [['', '', ''], ['', '', ''], ['', '', '']]
- assert game.board == expected_board
-
- # Verify initial player
- assert game.current_player == 'X'
-
- # Verify game status
- assert game.game_status == 'active'
-
- # Verify win conditions are not triggered
- assert game.winner is None
- assert game.winning_line is None
-
-
-def test_player_moves_and_turns(setup_game_state):
- """
- Test that players can make moves and turns alternate correctly.
-
- This test verifies the turn-based mechanics of the game where
- players X and O alternate turns properly.
- """
- game = setup_game_state
-
- # Player X makes a move
- result_x = game.make_move(0, 0)
- assert result_x is True
- assert game.board[0][0] == 'X'
- assert game.current_player == 'O'
-
- # Player O makes a move
- result_o = game.make_move(1, 1)
- assert result_o is True
- assert game.board[1][1] == 'O'
- assert game.current_player == 'X'
-
- # Player X makes another move
- result_x2 = game.make_move(0, 2)
- assert result_x2 is True
- assert game.board[0][2] == 'X'
- assert game.current_player == 'O'
-
+import logging
+from crm_5_implementation import app, HOST, PORT, DEBUG
-def test_invalid_move_handling(setup_game_state):
+@pytest.fixture
+def client():
"""
- Test that invalid moves are handled properly.
-
- This test verifies that attempting to make moves in invalid locations
- or when the game is over correctly returns False and doesn't change state.
- """
- game = setup_game_state
-
- # Try to make a move on an occupied cell
- game.make_move(0, 0)
- result = game.make_move(0, 0)
- assert result is False
-
- # Try to make a move outside board bounds
- result = game.make_move(5, 5)
- assert result is False
-
- # Try to make a move when game is already won
- game.make_move(0, 1)
- game.make_move(1, 0)
- game.make_move(0, 2) # X wins
- result = game.make_move(1, 1)
- assert result is False
-
-
-def test_win_condition_detection(setup_game_state):
+ Fixture to initialize the Flask test client.
+ Sets the application to testing mode and yields the client for integration requests.
"""
- Test that win conditions are detected correctly for all scenarios.
-
- This test verifies that the game correctly identifies wins in rows,
- columns, and diagonals.
- """
- game = setup_game_state
-
- # Test horizontal win for X
- game.make_move(0, 0) # X
- game.make_move(1, 0) # O
- game.make_move(0, 1) # X
- game.make_move(1, 1) # O
- game.make_move(0, 2) # X - Win!
-
- assert game.winner == 'X'
- assert game.game_status == 'won'
- assert game.winning_line == [0, 1, 2]
-
+ app.config['TESTING'] = True
+ with app.test_client() as client:
+ yield client
-def test_draw_condition(setup_game_state):
+def test_server_configuration_integrity():
"""
- Test that draw conditions are detected correctly.
-
- This test verifies that the game correctly identifies when the board
- is full with no winner, resulting in a draw.
+ Integration test to verify that the server configuration constants
+ defined in the implementation file are correctly assigned.
"""
- game = setup_game_state
-
- # Fill the board with alternating moves to create a draw
- moves = [
- (0, 0), (1, 1), (0, 1), (1, 0), (0, 2),
- (2, 1), (2, 0), (2, 2), (1, 2)
- ]
-
- for i, (row, col) in enumerate(moves):
- if i % 2 == 0:
- game.make_move(row, col) # X's turn
- else:
- game.make_move(row, col) # O's turn
-
- assert game.game_status == 'draw'
- assert game.winner is None
-
+ assert HOST == "0.0.0.0"
+ assert PORT == 5000
+ assert DEBUG is False
-def test_game_reset_functionality(setup_game_state):
+def test_index_route_accessibility(client):
"""
- Test that the game reset functionality works correctly.
-
- This test verifies that resetting the game returns it to its initial state
- and clears all previous game data.
+ Integration test for the root endpoint.
+ Ensures the Flask server is running and the index route returns a 200 OK status.
"""
- game = setup_game_state
-
- # Make some moves
- game.make_move(0, 0)
- game.make_move(1, 1)
-
- # Reset the game
- game.reset_game()
-
- # Verify reset state
- expected_board = [['', '', ''], ['', '', ''], ['', '', '']]
- assert game.board == expected_board
- assert game.current_player == 'X'
- assert game.game_status == 'active'
- assert game.winner is None
- assert game.winning_line is None
-
+ response = client.get('/')
+ assert response.status_code == 200
-def test_game_state_serialization(setup_game_state):
+def test_template_rendering_integration(client):
"""
- Test that game state can be properly serialized and deserialized.
-
- This test verifies that the game state can be converted to JSON format
- and reconstructed correctly.
+ Integration test to verify the connection between the Flask route and the
+ TIC_TAC_TOE_TEMPLATE. Checks if the HTML, CSS, and JS components are served.
"""
- game = setup_game_state
-
- # Make some moves
- game.make_move(0, 0)
- game.make_move(1, 1)
-
- # Serialize the game state
- state_dict = game.get_game_state()
+ response = client.get('/')
+ content = response.data.decode('utf-8')
- # Verify serialized state contains expected fields
- assert 'board' in state_dict
- assert 'current_player' in state_dict
- assert 'game_status' in state_dict
- assert 'winner' in state_dict
- assert 'winning_line' in state_dict
+ # Verify the page contains the game title
+ assert "Tic Tac Toe" in content
- # Verify specific values
- assert state_dict['board'][0][0] == 'X'
- assert state_dict['current_player'] == 'O'
- assert state_dict['game_status'] == 'active'
-
-
-def test_win_condition_edge_cases(setup_game_state):
- """
- Test win condition edge cases including diagonals and various board configurations.
-
- This test verifies that all win conditions (horizontal, vertical, diagonal)
- are correctly detected in various board configurations.
- """
- game = setup_game_state
+ # Verify the integration of CSS styles
+ assert "