diff --git a/rules_ut.py b/rules_ut.py new file mode 100644 index 0000000..1ca3293 --- /dev/null +++ b/rules_ut.py @@ -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() \ No newline at end of file diff --git a/src/rules.py b/src/rules.py index 05e20d7..0dd0475 100644 --- a/src/rules.py +++ b/src/rules.py @@ -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 - """ - correct = False + self.nb_row = 6 + self.nb_col = 7 - 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") + 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 + + if self.nb_col == board.nbcol and self.nb_row == board.nbrow : + correct = True + else: + correct = False + return correct diff --git a/test/rules_ut.py b/test/rules_ut.py deleted file mode 100644 index 29578f6..0000000 --- a/test/rules_ut.py +++ /dev/null @@ -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() \ No newline at end of file