Пример #1
0
 def test_configuration_victory(self):
     pieces = self.pieces
     # check a 2x2 block in the middle
     for i in range(1,3):
         for j in range(1,3):
             pieces[i][j] = player_piece(red())
     board = Position(pieces,black(),None)
     self.assertEqual(board.check_victory(),red())
     # now change the board so that black wins and red doesn't
     for i in range(4):
         pieces[i][i] = player_piece(black())
     # check that data is stored correctly
     self.assertEqual(board.check_victory(),red())
     # now check for real
     board = Position(pieces,black(),None)
     self.assertEqual(board.check_victory(),black())
Пример #2
0
 def test_configuration_victory(self):
     pieces = self.pieces
     # check a 2x2 block in the middle
     for i in range(1, 3):
         for j in range(1, 3):
             pieces[i][j] = player_piece(red())
     board = Position(pieces, black(), None)
     self.assertEqual(board.check_victory(), red())
     # now change the board so that black wins and red doesn't
     for i in range(4):
         pieces[i][i] = player_piece(black())
     # check that data is stored correctly
     self.assertEqual(board.check_victory(), red())
     # now check for real
     board = Position(pieces, black(), None)
     self.assertEqual(board.check_victory(), black())
Пример #3
0
 def test_doing_and_undoing(self):
     pieces = self.pieces
     board = Position(pieces, black(), None)
     move = Move(board, loc(0, 0))
     move.do()
     self.assertEqual(board.get_piece(0, 0), player_piece(black()))
     self.assertNotEqual(board.get_piece(0, 0), pieces[0][0])
     self.assertEqual(board.whose_move(), red())
     self.assertEqual(board.previous_piece, pieces[0][0])
     moves = board.get_moves()
     self.assertEqual(len(moves), 3 + 3)
     move.undo()
     self.assertEqual(board.get_piece(0, 0), pieces[0][0])
     self.assertEqual(board.previous_piece, None)
     self.assertEqual(board.whose_move(), black())
     moves = board.get_moves()
     self.assertEqual(len(moves), 4 * 4 - 2 * 2)
Пример #4
0
 def test_doing_and_undoing(self):
     pieces = self.pieces
     board = Position(pieces,black(),None)
     move = Move(board,loc(0,0))
     move.do()
     self.assertEqual(board.get_piece(0,0),
                      player_piece(black()))
     self.assertNotEqual(board.get_piece(0,0),pieces[0][0])
     self.assertEqual(board.whose_move(),red())
     self.assertEqual(board.previous_piece,pieces[0][0])
     moves = board.get_moves()
     self.assertEqual(len(moves),3+3)
     move.undo()
     self.assertEqual(board.get_piece(0,0),pieces[0][0])
     self.assertEqual(board.previous_piece,None)
     self.assertEqual(board.whose_move(),black())
     moves = board.get_moves()
     self.assertEqual(len(moves),4*4-2*2)