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