Skip to content

Commit

Permalink
Update test_checker.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 14, 2024
1 parent 826df45 commit 39b58e0
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions kyu_5/tic_tac_toe_checker/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import unittest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_5.tic_tac_toe_checker.checker import is_solved

Expand All @@ -27,7 +28,24 @@
class IsSolvedTestCase(unittest.TestCase):
"""Testing is_solved function."""

def test_is_solved(self):
@parameterized.expand(
[([[0, 0, 1],
[0, 1, 2],
[2, 1, 0]], -1, 'not yet finished'),
([[1, 1, 1],
[0, 2, 2],
[0, 0, 0]], 1, 'winning row'),
([[2, 1, 2],
[2, 1, 1],
[1, 1, 2]], 1, 'winning column'),
([[2, 1, 2],
[2, 1, 1],
[1, 2, 1]], 0, 'draw'),
([[1, 2, 0],
[0, 1, 2],
[0, 0, 1]], 1, 'wining diagonal')]
)
def test_is_solved(self, board, expected, message):
"""
Testing is_solved function with various test data.
Expand All @@ -54,25 +72,9 @@ def test_is_solved(self):
"<p>The function should return whether the board's "
"current state is solved.</p>")
# pylint: enable-msg=R0801
test_data: tuple = (
([[0, 0, 1],
[0, 1, 2],
[2, 1, 0]], -1, 'not yet finished'),
([[1, 1, 1],
[0, 2, 2],
[0, 0, 0]], 1, 'winning row'),
([[2, 1, 2],
[2, 1, 1],
[1, 1, 2]], 1, 'winning column'),
([[2, 1, 2],
[2, 1, 1],
[1, 2, 1]], 0, 'draw'),
([[1, 2, 0],
[0, 1, 2],
[0, 0, 1]], 1, 'wining diagonal'))

for board, expected, message in test_data:
with allure.step(f"Enter Tic-Tac-Toe board {board}"
f" and verify the output {expected}."):
result: int = is_solved(board)
with allure.step("Enter Tic-Tac-Toe board and verify the output."):
print_log(expected=expected, result=result, message=message)
self.assertEqual(expected, result, msg=message)
print_log(expected=expected, result=result, message=message)
self.assertEqual(expected, result, msg=message)

0 comments on commit 39b58e0

Please sign in to comment.