Exemple #1
0
class TestStaleMate(unittest.TestCase):
    def setUp(self):
        self.board = Board()
        for square in square_names:
            setattr(self.board, square, "empty")
        self.board.put("a1", "white king")
        self.board.put("b3", "black queen")

    def test_staleMate(self):
        self.assertTrue(self.board.is_stalemate("white"))

    def test_notMate_ifStaleMate(self):
        self.assertFalse(self.board.is_checkmated("white"))
Exemple #2
0
class TestFoolsMate(unittest.TestCase):
    def setUp(self):
        self.board = Board()
        self.board.move_if_legal("f2", "f3", "white")
        self.board.move_if_legal("e7", "e5", "black")
        self.board.move_if_legal("g2", "g4", "white")
        self.board.move_if_legal("d8", "h4", "black")

    def test_countLegalMovesAfterFoolsMate(self):
        self.assertEqual(0, self.board.count_legal_moves("white"))

    def test_countLegalMoves_inInitialPosition(self):
        self.board = Board()
        self.assertEqual(20, self.board.count_legal_moves("white"))
        self.assertEqual(20, self.board.count_legal_moves("black"))

    def test_checkMate_afterFoolsMate(self):
        self.assertTrue(self.board.is_checkmated("white"))
        self.assertFalse(self.board.is_checkmated("black"))

    def test_gameEndedWithBlackWin_afterWhiteIsCheckmated(self):
        self.assertTrue(self.board.game_ended)
        self.assertEqual("black wins", self.board.result)