def test_empty_second_input(): game = RockPaperScissors() for i in "RPS": with pytest.raises(GameInputException, message="Invalid Input. Please try again.\n"): game.judge(i, '') pass
def test_generate_valid_input(): game = RockPaperScissors() freq = {'R': False, 'P': False, 'S': False} for _ in range(1000): i = game.generate_input() assert game.is_valid_input(i) freq[i] = True assert freq['R'] assert freq['P'] assert freq['S']
def test_invalid_second_input_character(): game = RockPaperScissors() for c in range(128): char = chr(c).upper() if char not in "RPS": for i in "RPS": with pytest.raises( GameInputException, message="Invalid Input. Please try again.\n"): game.judge(i, char) pass
def get_full_name(a): inputmap = {'R': "Rock", 'P': "Paper", 'S': "Scissors"} if RockPaperScissors.is_valid_input(a): return inputmap[a] else: return a
from RockPaperScissorsGame import RockPaperScissors from GameInputException import GameInputException def get_full_name(a): inputmap = {'R': "Rock", 'P': "Paper", 'S': "Scissors"} if RockPaperScissors.is_valid_input(a): return inputmap[a] else: return a if __name__ == '__main__': game = RockPaperScissors() print("This is a rock paper scissors game.") while True: action = input("Play [R]ock, [P]aper, [S]cissors or [Q]uit\n").upper() if action == 'Q': print("Bye") quit(0) else: try: computer = game.generate_input() print("Your input: " + get_full_name(action)) print("Computer input: " + get_full_name(computer)) result = game.judge(action, computer) if result == 1: print("You won!\n") elif result == -1: print("You lost!\n") else:
def test_scissors_scissors(): game = RockPaperScissors() assert game.judge('S', 'S') == 0
def test_paper_scissors(): game = RockPaperScissors() assert game.judge('P', 'S') == -1
def test_check_input_rock(): game = RockPaperScissors() assert game.is_valid_input('R')
def test_paper_rock(): game = RockPaperScissors() assert game.judge('P', 'R') == 1
def test_rock_scissors(): game = RockPaperScissors() assert game.judge('R', 'S') == 1
def test_rock_paper(): game = RockPaperScissors() assert game.judge('R', 'P') == -1
def test_check_input_invalid_character(): game = RockPaperScissors() for c in range(128): char = chr(c).upper() if char not in "RPS": assert not game.is_valid_input(char)
def test_check_input_empty(): game = RockPaperScissors() assert not game.is_valid_input('')
def test_empty_both_inputs(): with pytest.raises(GameInputException, message="Invalid Input. Please try again.\n"): game = RockPaperScissors() game.judge('', '') pass