Exemplo n.º 1
0
    def test_move_flips_appropriate_pieces(self):
        r = Reversi('''
            - - - - - - - -
            - - - - - - - -
            - - - - - - - -
            - - - w b - - -
            - - - b w - - -
            - - - - - - - -
            - - - - - - - -
            - - - - - - - -
            ''')
        r.move('F5')  # black
        expected_board = '''
            - - - - - - - -
            - - - - - - - -
            - - - - - - - -
            - - - w b - - -
            - - - b b b - -
            - - - - - - - -
            - - - - - - - -
            - - - - - - - -
            '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())
        r.move('F6')  # white
        expected_board = '''
            - - - - - - - -
            - - - - - - - -
            - - - - - - - -
            - - - w b - - -
            - - - b w b - -
            - - - - - w - -
            - - - - - - - -
            - - - - - - - -
            '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())
        r.move('E6')  # black
        expected_board = '''
            - - - - - - - -
            - - - - - - - -
            - - - - - - - -
            - - - w b - - -
            - - - b b b - -
            - - - - b w - -
            - - - - - - - -
            - - - - - - - -
            '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())
        r.move('D6')  # white
        expected_board = '''
            - - - - - - - -
            - - - - - - - -
            - - - - - - - -
            - - - w b - - -
            - - - w b b - -
            - - - w w w - -
            - - - - - - - -
            - - - - - - - -
            '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())
        r.move('C3')  # black
        expected_board = '''
            - - - - - - - -
            - - - - - - - -
            - - b - - - - -
            - - - b b - - -
            - - - w b b - -
            - - - w w w - -
            - - - - - - - -
            - - - - - - - -
            '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())
        r.move('B2')  # white
        expected_board = '''
            - - - - - - - -
            - w - - - - - -
            - - w - - - - -
            - - - w b - - -
            - - - w w b - -
            - - - w w w - -
            - - - - - - - -
            - - - - - - - -
            '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())
        r.move('C5')  # black
        expected_board = '''
            - - - - - - - -
            - w - - - - - -
            - - w - - - - -
            - - - w b - - -
            - - b b b b - -
            - - - w w w - -
            - - - - - - - -
            - - - - - - - -
            '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())

        r = Reversi('''
            - - - b b b - -
            - - - - b b - -
            - - - b b b - -
            - - - b b b - -
            - w w w w b - -
            - - - b w w - -
            - - - - b w w -
            - - - - - - w w
            ''')
        r.player = 'b'
        r.move('F8')
        expected_board = '''
            - - - b b b - -
            - - - - b b - -
            - - - b b b - -
            - - - b b b - -
            - w w w w b - -
            - - - b w b - -
            - - - - b b w -
            - - - - - b w w
           '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())

        r = Reversi('''
            - - w b - w - -
            - - - w b w - -
            - - - b b w - -
            - - - b b w - -
            b b b b b w - -
            - - - b b w - -
            - - - - b w w -
            - - - - b - w w
            ''')
        r.player = 'w'
        r.move('E1')
        expected_board = '''
            - - w w w w - -
            - - - w b w - -
            - - - b b w - -
            - - - b b w - -
            b b b b b w - -
            - - - b b w - -
            - - - - b w w -
            - - - - b - w w
           '''
        expected_board = self.strip_leading_spaces(expected_board)
        self.assertEqual(
            expected_board, r.board_string(), "\nExpected: \n" +
            expected_board + "\nActual board: \n" + r.board_string())