def test_errors_can_print_input_not_numeric_error_message(): spy = PrinterSpy() error = Errors(spy) error.input_not_numeric_error_message() expected = "\nI didn't understand that ... trying entering a number: 1 - 9:\n" assert spy.printed() == expected
def test_errors_can_print_invalid_board_index_error_message(): spy = PrinterSpy() error = Errors(spy) error.invalid_board_index_error_message() expected = "\nSorry, friend ... that number isn't one of the squares. Please enter 1 - 9:\n" assert spy.printed() == expected
def test_errors_can_print_position_already_taken_error_message(): spy = PrinterSpy() error = Errors(spy) error.position_already_taken_error_message() expected = ( "\nOops, that square already has a token on it, please choose another one:\n" ) assert spy.printed() == expected
def test_user_interface_prints_logo_to_user(): spy = PrinterSpy() user_message = UserMessages(spy) user_message.logo() expected = """ ________________ _________ ______ __________ ______ /_ __/ _/ ____/ /_ __/ | / ____/ /_ __/ __ \\/ ____/ / / / // / / / / /| |/ / / / / / / / __/ / / _/ // /___ / / / ___ / /___ / / / /_/ / /___ /_/ /___/\\____/ /_/ /_/ |_\\____/ /_/ \\____/_____/""" assert spy.printed() == expected
def test_tic_tac_toe_display_board(): new_board = Board() view = CommandLineBoardPresenter() spy = PrinterSpy() view.display_board(new_board, spy) expected = """\ | | -------------- | | -------------- | | """ assert spy.printed() == expected
def test_user_interface_prints_example_vertical_win(): spy = PrinterSpy() user_message = UserMessages(spy) spy.print_item(user_message.instructions["vertically"]) expected = """\ \nvertically\n | X | -------------- | X | -------------- | X | """ assert spy.printed() == expected
def test_user_interface_prints_example_horizontal_win(): spy = PrinterSpy() user_message = UserMessages(spy) spy.print_item(user_message.instructions["horizontally"]) expected = """\ \neither horizontally\n X | X | X -------------- | | -------------- | | """ assert spy.printed() == expected
def test_tic_tac_toe_display_board_with_user_token(): new_board = Board() view = CommandLineBoardPresenter() spy = PrinterSpy() new_board.board = ["X", " ", " ", " ", "X", " ", " ", " ", "X"] view.display_board(new_board, spy) expected = """\ X | | -------------- | X | -------------- | | X """ assert spy.printed() == expected
def test_user_interface_prints_example_diagonal_win(): spy = PrinterSpy() user_message = UserMessages(spy) user_message.display_instructions() expected = user_message.instructions.values() for actual, expected in zip(spy.printed_items, expected): assert actual == expected
def test_user_interface_congratulates_winner(): spy = PrinterSpy() user_message = UserMessages(spy) board = Board() board.board = ["X", "O", " ", "X", "O", " ", "X", " ", " "] board.win() user_message.who_won(board) assert spy.printed_item == "X, you're the winner!"