* Corrected the macro for comments on the test file. * Added current_date (utcnow()) variable available for template macros. * Removed unnecessary datetime import from macros file. * Regenerated all practice exercise test files to add timestamp. * Changed `datetime.now(tz=timezone.utc)` to `datetime.now(tz=timezone.utc).date()` * Second regeneration to remove `timestamp` and just keep `date` for test files. [no important files changed]
117 lines
3.1 KiB
Python
117 lines
3.1 KiB
Python
import unittest
|
|
|
|
from connect import (
|
|
ConnectGame,
|
|
)
|
|
|
|
# These tests are auto-generated with test data from:
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/connect/canonical-data.json
|
|
# File last updated on 2023-07-14
|
|
|
|
|
|
class ConnectTest(unittest.TestCase):
|
|
def test_an_empty_board_has_no_winner(self):
|
|
game = ConnectGame(
|
|
""". . . . .
|
|
. . . . .
|
|
. . . . .
|
|
. . . . .
|
|
. . . . ."""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "")
|
|
|
|
def test_x_can_win_on_a_1x1_board(self):
|
|
game = ConnectGame("""X""")
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "X")
|
|
|
|
def test_o_can_win_on_a_1x1_board(self):
|
|
game = ConnectGame("""O""")
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "O")
|
|
|
|
def test_only_edges_does_not_make_a_winner(self):
|
|
game = ConnectGame(
|
|
"""O O O X
|
|
X . . X
|
|
X . . X
|
|
X O O O"""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "")
|
|
|
|
def test_illegal_diagonal_does_not_make_a_winner(self):
|
|
game = ConnectGame(
|
|
"""X O . .
|
|
O X X X
|
|
O X O .
|
|
. O X .
|
|
X X O O"""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "")
|
|
|
|
def test_nobody_wins_crossing_adjacent_angles(self):
|
|
game = ConnectGame(
|
|
"""X . . .
|
|
. X O .
|
|
O . X O
|
|
. O . X
|
|
. . O ."""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "")
|
|
|
|
def test_x_wins_crossing_from_left_to_right(self):
|
|
game = ConnectGame(
|
|
""". O . .
|
|
O X X X
|
|
O X O .
|
|
X X O X
|
|
. O X ."""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "X")
|
|
|
|
def test_o_wins_crossing_from_top_to_bottom(self):
|
|
game = ConnectGame(
|
|
""". O . .
|
|
O X X X
|
|
O O O .
|
|
X X O X
|
|
. O X ."""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "O")
|
|
|
|
def test_x_wins_using_a_convoluted_path(self):
|
|
game = ConnectGame(
|
|
""". X X . .
|
|
X . X . X
|
|
. X . X .
|
|
. X X . .
|
|
O O O O O"""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "X")
|
|
|
|
def test_x_wins_using_a_spiral_path(self):
|
|
game = ConnectGame(
|
|
"""O X X X X X X X X
|
|
O X O O O O O O O
|
|
O X O X X X X X O
|
|
O X O X O O O X O
|
|
O X O X X X O X O
|
|
O X O O O X O X O
|
|
O X X X X X O X O
|
|
O O O O O O O X O
|
|
X X X X X X X X O"""
|
|
)
|
|
winner = game.get_winner()
|
|
self.assertEqual(winner, "X")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|