def test_play_human(monkeypatch): # l’humain tape forcément la touche "6" s_in = StringIO("4\n") # <- simulation d’appui de la touche "6" monkeypatch.setattr("sys.stdin", s_in) rslt = morpy.play(predic_random, is_player=True, symbol="X") assert rslt == -1
def test_human_play(setup, result, monkeypatch): """Imite le joueur humain choisissant la position 5, avec indication s’il peut la jouer ou non""" s_in = StringIO("5") monkeypatch.setattr("sys.stdin", s_in) assert morpy.play("X", is_human=True) == result
def test_human_play_empty_board(monkeypatch): """Imite le joueur humain choisissant la position 5""" s_in = StringIO("5") monkeypatch.setattr("sys.stdin", s_in) assert morpy.play("X", is_human=True) == 5
def test_computer_play(rep, setup, result): """Doit retourner un chiffre représentant une case vide""" assert morpy.play("X") in result
def test_computer_play_empty_board(rep): """ Doit retourner un chiffre entre 1 et 9""" print(f"tentative n°{rep}") # inutile, mais pour le fun assert 1 <= morpy.play("X") <= 9
def test_play_computer_non_empty_2(attempt): rslt = morpy.play(win_board_o_slash, is_player=False, symbol="X") assert rslt not in [3, 5, 7]
def test_play_computer_non_empty(attempt): rslt = morpy.play(predic_random, is_player=False, symbol="X") assert rslt in [3, 6, 9]
def test_play_computer(attempt): rslt = morpy.play(empty_board, is_player=False, symbol="X") assert 1 <= rslt <= 9