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)
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)
def test_data_storage(self): pieces = self.pieces board = Position(pieces,red(),None) self.assertEqual(red(),board.whose_move()) for i in range(4): for j in range(4): self.assertEqual(pieces[i][j],board.get_piece(i,j)) p = pieces[2][3] for i in range(4): for j in range(4): pieces[i][j] = None self.assertEqual(p,board.get_piece(2,3))
def test_data_storage(self): pieces = self.pieces board = Position(pieces, red(), None) self.assertEqual(red(), board.whose_move()) for i in range(4): for j in range(4): self.assertEqual(pieces[i][j], board.get_piece(i, j)) p = pieces[2][3] for i in range(4): for j in range(4): pieces[i][j] = None self.assertEqual(p, board.get_piece(2, 3))
def test_tile_count_midgame(self): board = Position(self.pieces, black(), None) nMoves = 3 # do 3 random moves for i in range(nMoves): board.get_moves().pop().do() pieces = [[None for i in range(4)] for j in range(4)] for i in range(4): for j in range(4): pieces[i][j] = board.get_piece(i, j) board = Position(pieces, board.whose_move(), board.previous_piece) self.assertEqual(board.tile_count, 4 * 4 - nMoves)
def test_tile_count_midgame(self): board = Position(self.pieces,black(),None) nMoves = 3 # do 3 random moves for i in range(nMoves): board.get_moves().pop().do() pieces = [[None for i in range(4)] for j in range(4)] for i in range(4): for j in range(4): pieces[i][j] = board.get_piece(i,j) board = Position(pieces,board.whose_move(), board.previous_piece) self.assertEqual(board.tile_count,4*4-nMoves)