def test_flip_pieces(self): r = Reversi(''' - - - - - - - - - - - - - - - - - - w - w - - - - - w w w w - - - - w b b b b b - - - b b w - - - - - w b - - - - - w - b - - - ''') r.flip_pieces('south', 'b', 'D3') expected_board = ''' - - - - - - - - - - - - - - - - - - w - w - - - - - w b w w - - - - w b b b b b - - - b b w - - - - - w b - - - - - w - 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 = Reversi(''' - - - - - - - - - - - - - - - - - b b b - - - - - - b b b - - - - - w w w - - - - - - w - - - - - - - w - - - - - - - - - - - - ''') r.flip_pieces('south_east', 'w', 'B2') expected_board = ''' - - - - - - - - - - - - - - - - - b w b - - - - - - b w b - - - - - w w 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 w w w w - w w w w w w w w w b w w w - - - - - - w - - - - - - - b b b - - ''') r.flip_pieces('north_west', 'b', 'F6') r.flip_pieces('west', 'b', 'F6') expected_board = ''' - - - b - - - - - - b b - - - - - b b b - - - - - b b b w w w - w w w w b w w w w b b b b - - - - - - w - - - - - - - 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())
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())