class TestPiece(unittest.TestCase): """ Testing a piece functionality with a board set to it. """ def setUp(self): """ setup the test with 1 piece on a board. :return: None. """ self.piece = Piece() self.piece.board = Board(4, 4, [self.piece]) def test_row(self): """ test the row getter. :return: None. """ self.assertEqual(self.piece.row, 0) def test_set_row(self): """ test the row setter. :return: None. """ self.setUp() self.piece.row = 2 self.assertEqual(self.piece.row, 2) with self.assertRaises(InvalidMoveException): self.piece.row = -1 with self.assertRaises(InvalidMoveException): self.piece.row = 4 def test_column(self): """ test the column getter. :return: None. """ self.assertEqual(self.piece.column, 0) def test_set_column(self): """ test the column setter. :return: None. """ self.setUp() self.piece.column = 2 self.assertEqual(self.piece.column, 2) with self.assertRaises(InvalidMoveException): self.piece.column = -1 with self.assertRaises(InvalidMoveException): self.piece.column = 4 def test_set_position(self): """ test the position setting functionality. :return: None. """ self.setUp() self.piece.set_position(2, 2) self.assertEqual(self.piece.row, 2) self.assertEqual(self.piece.column, 2) with self.assertRaises(InvalidMoveException): self.piece.set_position(-1, 2) with self.assertRaises(InvalidMoveException): self.piece.set_position(2, -1) with self.assertRaises(InvalidMoveException): self.piece.set_position(-1, -1) with self.assertRaises(InvalidMoveException): self.piece.set_position(4, 2) with self.assertRaises(InvalidMoveException): self.piece.set_position(2, 4) with self.assertRaises(InvalidMoveException): self.piece.set_position(4, 4) def test_get_moves(self): """ test getting the available moves of a piece. :return: None. """ self.assertEqual(self.piece.get_moves(), []) def test_update_column_status(self): """ test updating the column `taken` value. :return: None. """ self.setUp() self.piece.update_column_status() self.assertEqual(self.piece.board[0, 1].taken, False) def test_can_move(self): """ test the can_move functionality of a piece. :return: None. """ self.assertEqual(self.piece.can_move(0, 0, 1), True) def test_move(self): """ test the move functionality of a piece. :return: None. """ self.setUp() self.piece.move(0, 1) self.assertEqual(self.piece.row, 0) self.assertEqual(self.piece.column, 1) self.assertEqual(self.piece.board[0, 1].piece, self.piece)
class TestPieceNoBoard(unittest.TestCase): """ Testing piece functionality without a board set to it. """ def setUp(self): """ setup the test with Piece class. :return: None. """ self.piece = Piece() def test_row(self): """ test the row getter. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.row def test_set_row(self): """ test the row setter. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.row = 1 def test_column(self): """ test the column getter. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.column def test_set_column(self): """ test the column setter. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.column = 1 def test_set_position(self): """ test the position setting functionality. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.set_position(1, 1) def test_get_moves(self): """ test getting the available moves of a piece. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.get_moves() def test_update_column_status(self): """ test updating the column `taken` value. :return: None. """ self.assertEqual(self.piece.update_column_status(), None) def test_can_move(self): """ test the can_move functionality of a piece. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.can_move(1, 1, 1) def test_move(self): """ test the move functionality of a piece. :return: None. """ with self.assertRaises(InvalidSetupException): self.piece.move(1, 1)