def test_unitvector_diagonal(self):
        extendedvector = core.Vector(5, 5)

        self.assertEqual(
            extendedvector.unitvector(), core.Vector(1, 1),
            errormessage(extendedvector.unitvector(), core.Vector(1, 1)))
        return None
 def test_checkAllAreVectors_goodinput(self):
     vectorlist = [core.Vector(1, 3), core.Vector(5, 1), core.Vector(0, 6)]
     try:
         self.piece._checkAllAreVectors(vectorlist)
     except Exception as error:
         self.fail("%s" % error)
     return
    def test_unitvector_filevector(self):
        extendedvector = core.Vector(0, 5)

        self.assertEqual(
            extendedvector.unitvector(), core.Vector(0, 1),
            errormessage(extendedvector.unitvector(), core.Vector(0, 1)))
        return None
    def test_unitvector_rankvector(self):
        extendedvector = core.Vector(5, 0)

        self.assertEqual(
            extendedvector.unitvector(), core.Vector(1, 0),
            errormessage(extendedvector.unitvector(), core.Vector(1, 0)))
        return None
    def test_parallelto(self):
        parallelvector = core.Vector(3, 6)
        othervector = core.Vector(5, 2)

        self.assertTrue(self.vector.parallelto(parallelvector))
        self.assertFalse(self.vector.parallelto(othervector))
        return None
    def setUp(self):
        self.vector1 = core.Vector(1, 2)
        self.vector2 = core.Vector(3, 4)
        self.scalar1 = 3

        self.vectorans = 11
        self.scalarans = core.Vector(3, 6)
        return None
 def test_notationtopositions(self):
     notation1 = 'e7->e8'
     notation2 = 'c1->a2'
     func = self.board._notationtopositions
     self.assertEqual((core.Vector(6, 4), core.Vector(7, 4)),
                      func(notation1))
     self.assertEqual((core.Vector(0, 2), core.Vector(1, 0)),
                      func(notation2))
     return None
Esempio n. 8
0
 def __init__(self, colour):
     super(self.__class__,
           self).__init__(colour=colour,
                          notationsymbol='B',
                          moveunitvectors=(core.Vector(1, 1),
                                           core.Vector(1, -1),
                                           core.Vector(-1, -1),
                                           core.Vector(-1, 1)))
     return None
    def test_position(self):
        # TODO: Goood and bad input checks.
        self.piece.movetoindex(33)
        self.assertEqual(33, self.piece.position(indexform=True))

        self.piece.movetovector(core.Vector(4, 5))
        self.assertEqual(core.Vector(4, 5),
                         self.piece.position(vectorform=True))
        return
Esempio n. 10
0
    def __init__(self, colour):
        if colour == 'white': movevector = core.Vector(1, 0)
        elif colour == 'black': movevector = core.Vector(-1, 0)
        else: raise core.ColourError()

        super(self.__class__, self).__init__(colour=colour,
                                             notationsymbol="P",
                                             crawler=True,
                                             moveunitvectors=(movevector, ))
        return None
 def test_processusermove_King(self):
     startpos = core.Vector(4, 4)
     endpos = core.Vector(5, 4)
     piece = pieces.KingPiece
     string = 'Ke5>e6'
     self.assertEqual(
         self.ui.processusermove(string),
         (piece, (startpos, endpos))
     )
     return None
 def test_processusermove_Queen(self):
     startpos = core.Vector(2, 3)
     endpos = core.Vector(3, 4)
     piece = pieces.QueenPiece
     string = 'Qd3>e4'
     self.assertEqual(
         self.ui.processusermove(string),
         (piece, (startpos, endpos))
     )
     return None
 def test_processusermove_Bishop(self):
     startpos = core.Vector(0, 7)
     endpos = core.Vector(1, 6)
     piece = pieces.BishopPiece
     string = 'Bh1>g2'
     self.assertEqual(
         self.ui.processusermove(string),
         (piece, (startpos, endpos))
     )
     return None
 def test_processusermove_Knight(self):
     startpos = core.Vector(0, 5)
     endpos = core.Vector(2, 4)
     piece = pieces.KnightPiece
     string = 'Nf1>e3'
     self.assertEqual(
         self.ui.processusermove(string),
         (piece, (startpos, endpos))
     )
     return None
 def test_processusermove_Rook(self):
     startpos = core.Vector(0, 0)
     endpos = core.Vector(5, 0)
     piece = pieces.RookPiece
     string = 'Ra1>a6'
     self.assertEqual(
         self.ui.processusermove(string),
         (piece, (startpos, endpos))
     )
     return None
 def test_processusermove_Pawn(self):
     startpos = core.Vector(1, 4)
     endpos = core.Vector(3, 4)
     piece = pieces.PawnPiece
     string = 'Pe2>e4'
     self.assertEqual(
         self.ui.processusermove(string),
         (piece, (startpos, endpos))
     )
     return None
Esempio n. 17
0
 def test_colournotvalid(self):
     with self.assertRaises(TypeError):
         pieces.BasePiece(
         'w', 'a', [core.Vector(0, 1)], crawler=True)
     with self.assertRaises(TypeError):
         pieces.BasePiece(
         10, 'a', [core.Vector(0, 1)], crawler=True)
     with self.assertRaises(TypeError):
         pieces.BasePiece(
         int, 'a', [core.Vector(0, 1)], crawler=True)
     return None
    def test_toindex_badinput(self):
        badinput1 = 'string'
        badinput2 = 14.09
        badinput3 = [core.Vector(1, 3), core.Vector(5, 3)]  # No lists.
        badinput4 = (2, 5)  # Doesn't accept coordinates.

        self.assertRaises(TypeError, self.piece._toindex, badinput1)
        self.assertRaises(TypeError, self.piece._toindex, badinput2)
        self.assertRaises(TypeError, self.piece._toindex, badinput3)
        self.assertRaises(TypeError, self.piece._toindex, badinput3)
        return
Esempio n. 19
0
    def runenpassanttest(self, indexpawnpiecetotest):
        """Each tuple is (piece, startindex, playerside)"""
        print ""
        print "Here is the board:\n"
        self.board.displayboard()
        print "\nTEST: EN PASSANT."
        print "================================"

        if indexpawnpiecetotest in range(32, 39+1):
            endpos = indexpawnpiecetotest
            (capturerank, capturefile) = self.convert(endpos+8, tocoordinate=True)
        elif indexpawnpiecetotest in range(24, 31+1):
            endpos = indexpawnpiecetotest
            (capturerank, capturefile) = self.convert(endpos-8, tocoordinate=True)
        else:
            raise IndexError("The index isn't valid")

        pawnonplayerside = self.board[endpos].isplayerpiece

        if pawnonplayerside:
            possiblemoves = self.board.allpossiblemoves(forplayerpieces=False)
        else:
            possiblemoves = self.board.allpossiblemoves(forplayerpieces=True)

        if self.board[endpos-1] != None:
            piece = self.board[endpos-1]
            movelist = possiblemoves[piece]
            if core.Vector(capturerank, capturefile) in movelist:
                strleft = 'can'
            else:
                strleft = "can't"
        else:
            strleft = "can't"
        if self.board[endpos+1] != None:
            piece = self.board[endpos+1]
            movelist = possiblemoves[piece]
            if core.Vector(capturerank, capturefile) in movelist:
                strright = 'can'
            else:
                strright = "can't"
        else:
            strright = "can't"

        print "The pawn at index %i %s be captured on the left and %s be captured on the right." % (indexpawnpiecetotest, strleft, strright)
        check = raw_input("Does that seem right? [y/n]: ")
        while check.lower() not in ('y', 'n'):
            check = raw_input("Type either 'y' or 'n' to proceed.")
        if check.lower() == 'n':
            self.fail("The king castled badly!")
        else:
            print "Test passed!"
            print "--------------------------------------------------------\n"
        return None
    def test_positiontonotation(self):
        func = self.board._positiontonotation
        # First position.
        self.assertEqual('e1->e2', func(4, 12))
        self.assertEqual('e1->e2', func((0, 4), (1, 4)))
        self.assertEqual('e1->e2', func(core.Vector(0, 4), core.Vector(1, 4)))

        # Second position.
        self.assertEqual('f7xg7', func(53, 54, capture=True))
        self.assertEqual('f7xg7', func((6, 5), (6, 6), capture=True))
        self.assertEqual(
            'f7xg7', func(core.Vector(6, 5), core.Vector(6, 6), capture=True))
        return
Esempio n. 21
0
    def test_PiecesOnSameFile(self):
        file_ = randint(0, 7)  # Pick a file randomly.
        rank1 = randint(0, 7)
        rank2 = randint(0, 7)
        while rank1 == rank2:  # Don't let the pieces be on the same square.
            rank2 = randint(0, 7)

        startpos1 = self.convert(core.Vector(rank1, file_), toindex=True)
        startpos2 = self.convert(core.Vector(rank2, file_), toindex=True)

        self.runmovementtestforpieces(
            ((core.RookPiece, startpos1), (core.RookPiece, startpos2))
        )
        return None
Esempio n. 22
0
    def test_PiecesOnSameRank(self):
        rank = randint(0, 7)  # Pick a rank randomly.
        file1 = randint(0, 7)
        file2 = randint(0, 7)
        while file1 == file2:  # Don't let the pieces be on the same square.
            file2 = randint(0, 7)

        startpos1 = self.convert(core.Vector(rank, file1), toindex=True)
        startpos2 = self.convert(core.Vector(rank, file2), toindex=True)

        self.runmovementtestforpieces(
            ((core.RookPiece, startpos1), (core.RookPiece, startpos2))
        )
        return None
    def test_checkAllAreVectors_badinput(self):
        badlist1 = [(2, 5), (6, 0), (7, 7)]  # Coordinates instead of vectors.
        badlist2 = ['strings', 'are', 'not', 'good']  # Strings instead of.
        badlist3 = ['some are strings', core.Vector(1, 2), (6, 5)]  # Mixed.
        badlist4 = core.Vector(7, 1)  # Not a list.

        self.assertRaises(AssertionError, self.piece._checkAllAreVectors,
                          badlist1)
        self.assertRaises(AssertionError, self.piece._checkAllAreVectors,
                          badlist2)
        self.assertRaises(AssertionError, self.piece._checkAllAreVectors,
                          badlist3)
        self.assertRaises(TypeError, self.piece._checkAllAreVectors, badlist4)
        return
    def test__setitem__vector(self):
        piece = pieces.QueenPiece('white')
        self.board[core.Vector(6, 6)] = piece

        self.assertEqual(self.board._board[54], piece,
                         errormessage(self.board._board[54], piece))
        return None
 def test_tovector_goodinput(self):
     index = 44  # Magic number to be certain the output is right.
     expectedvector = core.Vector(5, 4)
     self.assertEqual(
         expectedvector, self.piece._tovector(index),
         "The vector calculated doesn't match that as expected.")
     return
Esempio n. 26
0
 def test_notationsymbol_black(self):
     piece = pieces.BasePiece('black', 'a', [core.Vector(0, 1)], crawler=True)
     self.assertEqual(
         piece.notationsymbol, 'a',
         errormessage(piece.notationsymbol, 'a')
     )
     return None
 def test_assertPositionOnBoard_badinput(self):
     testfunc = self.board._assertPositionOnBoard
     self.assertRaises(TypeError, testfunc, 'string')  # String
     self.assertRaises(TypeError, testfunc, 13.11)  # Float.
     self.assertRaises(AssertionError, testfunc, (8, 4))  # Tuple off board.
     self.assertRaises(AssertionError, testfunc,
                       core.Vector(-3, 5))  # Vector off board.
     return None
    def test_toindex_goodinput(self):
        vector = core.Vector(2, 2)
        expectedindex = 18  # Magic numbers to be certain of correct answer.

        self.assertEqual(
            expectedindex, self.piece._toindex(vector),
            "The output of _toindex didn't match expected result.")
        return
 def setUp(self):
     self.piece = core.BasePiece(playerpiece=True,
                                 startpositionindex=choice(
                                     self.innersquares()),
                                 notationsymbol='?',
                                 validmovevectors=(core.Vector(1, 0), ),
                                 onlyunitvectors=True)
     return None
Esempio n. 30
0
 def __init__(self, colour):
     super(self.__class__, self).__init__(
         colour=colour,
         notationsymbol='N',
         crawler=True,
         moveunitvectors=(core.Vector(2, 1), core.Vector(1, 2),
                          core.Vector(2, -1), core.Vector(1, -2),
                          core.Vector(-2, -1), core.Vector(-1, -2),
                          core.Vector(-2, 1), core.Vector(-1, 2)))
     return None