def test_xy_conv(self): """Tests for conversion from xy arrray positions to board indices.""" pos1 = [0, 0] # a8 pos2 = [7, 7] # h1 pos3 = [4, 5] # e3 pos_inv1 = [64, 0] pos_inv2 = [0, 9] self.assertEqual(xy_to_num(pos1), 0) self.assertEqual(xy_to_num(pos2), 63) self.assertEqual(xy_to_num(pos3), 44) self.assertFalse(xy_to_num(pos_inv1)) self.assertFalse(xy_to_num(pos_inv2))
def test_add_to_board(self): """Add a piece, verify the square is taken and that the board's pieces list has the piece in it.""" board, white = Board(), Player(Color.W) pos_white = [4, 6] # e2 pawn_white = Pawn(white, pos_white) board.add_to_board(pawn_white) # fetch the piece using xy_conversion self.assertTrue(board.board[xy_to_num(pos_white)] is pawn_white) # assure that the piece is in the board's pieces list. self.assertTrue(pawn_white in board.pieces)