class TestControllerCheckTie(unittest.TestCase): """ Check for controller for the situation of a a tie, full board """ def setUp(self): """Inits empty grid for testing""" self.controller = Controller() def tearDown(self): """ Closes the controller """ del self.controller @patch('sys.stdout', new_callable=StringIO) def test_if_tie_completely_full(self, mock_stdout): """ Check if board is completely full call show_tie and print that it's a tie """ self.controller.board = [ ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ] tie_print = "Yay! It's a tie! (^-^)\n" self.controller.check_tie() self.assertEqual(tie_print, mock_stdout.getvalue()) @patch('sys.stdout', new_callable=StringIO) def test_if_tie_partially_full(self, mock_stdout): """ Check if board is partially full call show_tie and print that it's a tie """ self.controller.board = [ [" "] * 3 + ["\u25CF"] * 3, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ["\u25CF"] * 6, ] tie_print = "Yay! It's a tie! (^-^)\n" self.controller.check_tie() self.assertNotEqual(tie_print, mock_stdout.getvalue())
def setUp(self): """Inits empty grid for testing""" self.controller = Controller()
class TestControllerCheckWinner(unittest.TestCase): """ Checks the controller's logic for the situation of a win. """ def setUp(self): """Inits empty grid for testing""" self.controller = Controller() def tearDown(self): """ Closes the view """ del self.controller def test_if_winner_column_player_a(self): """ Check for a vertical win player A """ self.controller.board = [ [" "] * 6, [" "] * 6, [" "] * 6, [" "] * 6, [" "] * 6, [" "] * 2 + ["\u25CF"] * 4, [" "] * 6 ] self.assertTrue(self.controller.check_winner()) def test_if_winner_column_player_b(self): """ Check for a vertical win Player B """ self.controller.board = [ [" "] * 6, [" "] * 6, [" "] * 6, [" "] * 6, [" "] * 6, [" "] * 2 + ["\u25CB"] * 4, [" "] * 6 ] self.assertFalse(self.controller.check_winner()) def test_if_winner_row_player_A(self): """ Check for a horizontal win Player A """ self.controller.board = [ [" "] * 6, [" "] * 6, [" "] * 6, [" "] * 5 + ["\u25CF"] * 1, [" "] * 5 + ["\u25CF"] * 1, [" "] * 5 + ["\u25CF"] * 1, [" "] * 5 + ["\u25CF"] * 1, ] self.assertTrue(self.controller.check_winner()) def test_if_winner_diag_player_a(self): """ Check for a diagonal win Player A """ self.controller.board = [ [" "] * 5 + ["\u25CF"] * 1, [" "] * 4 + ["\u25CF"] * 1 + [" "] * 1, [" "] * 3 + ["\u25CF"] * 1 + [" "] * 2, [" "] * 2 + ["\u25CF"] * 1 + [" "] * 3, [" "] * 1 + ["\u25CF"] * 1 + [" "] * 4, [" "] * 6, [" "] * 6 ] self.assertTrue((self.controller.check_winner())) def test_if_winner_player_a_other_way(self): """ Check for other diagonal win Player A """ self.controller.board = [ [" "] * 6, [" "] * 6, [" "] * 1 + ["\u25CF"] * 1 + [" "] * 4, [" "] * 2 + ["\u25CF"] * 1 + [" "] * 3, [" "] * 3 + ["\u25CF"] * 1 + [" "] * 2, [" "] * 4 + ["\u25CF"] * 1 + [" "] * 1, [" "] * 5 + ["\u25CF"] * 1 ] self.assertTrue((self.controller.check_winner()))