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:
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.nb_row = None
|
||||
self.nb_col = None
|
||||
|
||||
def check_board_size(self, board: Board) -> Bool:
|
||||
""" Checks if the board size is correct.
|
||||
Entries:
|
||||
self: the Rules class itself
|
||||
board -> Board: a board
|
||||
Output:
|
||||
correct -> Bool: if True, the board size is correct
|
||||
"""
|
||||
self.nb_row = 6
|
||||
self.nb_col = 7
|
||||
|
||||
def check_board_size(self, board):
|
||||
""" Checks if the board size is correct.
|
||||
Entries:
|
||||
self: the Rules class itself
|
||||
board -> Board: a board
|
||||
Output:
|
||||
correct -> Bool: if True, the board size is correct
|
||||
"""
|
||||
correct = False
|
||||
|
||||
try:
|
||||
if self.nb_col == board.nb_col and self.nb_row == board.nb_row :
|
||||
correct = True
|
||||
except Exception:
|
||||
print("Exception: check_board_size: col and row parameters might are compared to another type")
|
||||
|
||||
if self.nb_col == board.nbcol and self.nb_row == board.nbrow :
|
||||
correct = True
|
||||
else:
|
||||
correct = False
|
||||
|
||||
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