forked from thomas.barbier/connect4
parent
95bdef0c99
commit
e314a81e69
@ -0,0 +1,25 @@
|
|||||||
|
import unittest
|
||||||
|
from parameterized import parameterized
|
||||||
|
|
||||||
|
from src.rules import Rules
|
||||||
|
from src.board import Board
|
||||||
|
|
||||||
|
class TestRules(unittest.TestCase):
|
||||||
|
@parameterized.expand([
|
||||||
|
(6, 7, True),
|
||||||
|
(10, 10, False),
|
||||||
|
('6', '7', False),
|
||||||
|
(7, '1', False),
|
||||||
|
('1', 6, False),
|
||||||
|
])
|
||||||
|
def test_check_board_size(self, row, col, no_exception):
|
||||||
|
rules = Rules()
|
||||||
|
board = Board(row, col)
|
||||||
|
|
||||||
|
if no_exception:
|
||||||
|
self.assertTrue(rules.check_board_size(board))
|
||||||
|
else:
|
||||||
|
self.assertFalse(rules.check_board_size(board))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
@ -1,23 +1,25 @@
|
|||||||
|
from src.board import Board
|
||||||
|
|
||||||
class Rules:
|
class Rules:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = None
|
|
||||||
self.nb_row = None
|
|
||||||
self.nb_col = None
|
|
||||||
|
|
||||||
def check_board_size(self, board: Board) -> Bool:
|
self.nb_row = 6
|
||||||
""" Checks if the board size is correct.
|
self.nb_col = 7
|
||||||
Entries:
|
|
||||||
self: the Rules class itself
|
|
||||||
board -> Board: a board
|
|
||||||
Output:
|
|
||||||
correct -> Bool: if True, the board size is correct
|
|
||||||
"""
|
|
||||||
correct = False
|
|
||||||
|
|
||||||
try:
|
def check_board_size(self, board):
|
||||||
if self.nb_col == board.nb_col and self.nb_row == board.nb_row :
|
""" Checks if the board size is correct.
|
||||||
correct = True
|
Entries:
|
||||||
except Exception:
|
self: the Rules class itself
|
||||||
print("Exception: check_board_size: col and row parameters might are compared to another type")
|
board -> Board: a board
|
||||||
|
Output:
|
||||||
|
correct -> Bool: if True, the board size is correct
|
||||||
|
"""
|
||||||
|
correct = False
|
||||||
|
|
||||||
|
|
||||||
|
if self.nb_col == board.nbcol and self.nb_row == board.nbrow :
|
||||||
|
correct = True
|
||||||
|
else:
|
||||||
|
correct = False
|
||||||
|
|
||||||
return correct
|
return correct
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
import unittest
|
|
||||||
from parametrized import parametrized
|
|
||||||
|
|
||||||
from src.rules import Rules
|
|
||||||
|
|
||||||
class TestRules(unittest.TestCase):
|
|
||||||
@parameterized([
|
|
||||||
('Joe', 7, 6, True),
|
|
||||||
('Joe', 10, 10, False),
|
|
||||||
('Joe', '7', '6', False),
|
|
||||||
('Joe', 7, '1', False),
|
|
||||||
('Joe', '1', 6, False),
|
|
||||||
])
|
|
||||||
def test_check_board_size(self, name, col, row, no_exception=False):
|
|
||||||
Rules rules
|
|
||||||
Board board(name, col, row)
|
|
||||||
|
|
||||||
if no_exception:
|
|
||||||
try:
|
|
||||||
rules.check_board_sizes(board)
|
|
||||||
except Exception:
|
|
||||||
self.assertEqual(no_exception, False)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
Loading…
Reference in new issue