Exemplo n.º 1
0
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
Exemplo n.º 2
0
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']
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def get_full_name(a):
    inputmap = {'R': "Rock", 'P': "Paper", 'S': "Scissors"}
    if RockPaperScissors.is_valid_input(a):
        return inputmap[a]
    else:
        return a
Exemplo n.º 5
0
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:
Exemplo n.º 6
0
def test_scissors_scissors():
    game = RockPaperScissors()
    assert game.judge('S', 'S') == 0
Exemplo n.º 7
0
def test_paper_scissors():
    game = RockPaperScissors()
    assert game.judge('P', 'S') == -1
Exemplo n.º 8
0
def test_check_input_rock():
    game = RockPaperScissors()
    assert game.is_valid_input('R')
Exemplo n.º 9
0
def test_paper_rock():
    game = RockPaperScissors()
    assert game.judge('P', 'R') == 1
Exemplo n.º 10
0
def test_rock_scissors():
    game = RockPaperScissors()
    assert game.judge('R', 'S') == 1
Exemplo n.º 11
0
def test_rock_paper():
    game = RockPaperScissors()
    assert game.judge('R', 'P') == -1
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
def test_check_input_empty():
    game = RockPaperScissors()
    assert not game.is_valid_input('')
Exemplo n.º 14
0
def test_empty_both_inputs():
    with pytest.raises(GameInputException,
                       message="Invalid Input. Please try again.\n"):
        game = RockPaperScissors()
        game.judge('', '')
    pass