Пример #1
0
   def test_PieceMovement(self):
      black = Util.colors.BLACK
      piece = Piece("Bishop", black, "")
      success = piece.move("b5")
      self.assertFalse(success)
      self.assertFalse(piece.moved)
      self.assertEqual(piece.moveResultReason, "Piece has not been placed on the board.")

      piece = Piece("Bishop", black , "b5")
      success = piece.move("c10")
      self.assertFalse(success)
      self.assertFalse(piece.moved)
      self.assertEqual(piece.moveResultReason, "Destination is not a valid chess square.")

      success = piece.move("c5")
      self.assertTrue(success)
      self.assertTrue(piece.moved)
      self.assertEqual(piece.position, "c5")
      self.assertEqual(piece.moveResultReason, "Success")
Пример #2
0
 def test_PieceLetter(self):
    for pieceName in Util.pieces:
       piece = Piece(pieceName, Util.colors.WHITE, "a1")
       self.assertEqual(piece.getPieceLetter(), Util.pieces[pieceName])
    piece = Piece("Mike", Util.colors.WHITE, "a1")
    self.assertEqual(piece.getPieceLetter(), " ")
    piece = Piece("", Util.colors.WHITE, "a1")
    self.assertEqual(piece.getPieceLetter(), " ")
Пример #3
0
 def test_PieceUndoMovement(self):
    white = Util.colors.WHITE
    previousLocation = "b5"
    piece = Piece("Rook", white, previousLocation)
    movements = [("c2", False), ("g4", True), ("a8", True)]
    for move, movedPreviously in movements:
       piece.move(move)
       self.assertTrue(piece.moved)
       self.assertEqual(piece.position, move)
       self.assertEqual(piece.lastMove, (previousLocation, movedPreviously))
       piece.undoLastMove()
       self.assertEqual(piece.moved, movedPreviously)
       self.assertEqual(piece.position, previousLocation)
       piece.move(move)
       self.assertTrue(piece.moved)
       self.assertEqual(piece.position, move)
       self.assertEqual(piece.lastMove, (previousLocation, movedPreviously))
       previousLocation = move