Testing for gameplay issues (Rock, Paper, Scissors)

Hello everyone,

Very nice to be here, recently signed up. I have an issue with a Rock, Paper Scissors (RPS) game and I would like to know how it could be solved with testing. I have not pasted the code because I’m looking for more conceptual advice, although I can and will do if required. Anyway, I have this output:

Type Rock, Paper, Scissors or q to quit: rock
Type Rock, Paper, Scissors or q to quit: paper
Type Rock, Paper, Scissors or q to quit: scissors
Type Rock, Paper, Scissors or q to quit: q # The same successfully quits here

As you can see, Typing in either RPS does not start the game. Having looked at the code I cannot see what the issue is, but there might be something glaringly obvious. However, I would like to figure out this problem through using testing methods, because I think it would serve well when it comes to bigger code that is difficult to scan/eyeball (if that makes sense). Is this feasible?

Through testing I understand you can pry out issues and see what is going on in your code. Maybe this sort of error (logic error as I understand it) may not be so easy to figure out through testing? Anyway, would it be worth delving into testing methods to figure this stuff out and see the workings of the code better? Any advice, tutorials and resources appreciated.

Ta Muchly.

Abstract away the input() command(s) into a wrapper function, and refactor to call it everywhere needed. For testing, swap that wrapper function for one with the same call signature, that takes the user’s input from a file of test data.

1 Like

Make sure that you prompt the user to enter the correct information that matches the available options. For example, in:

Type Rock, Paper, Scissors or q to quit:

Notice how all of the words are capitalized yet what you have entered as entries are all lower case. In your test script, have you accounted for this? For example, say you have listed the potential entries that are valid for the game to continue, are the following options in your list (tuple) include both capitalized and non-capitalized responses?

rps_entries = ('Rock', 'rock', 'Paper', 'paper', 'Scissors', 'scissors')

Or something like this where you auto-capitalize the user’s responses:

# Then can have upper case options only in look-up tuple
rps_entries = ('Rock', 'Paper', 'Scissors')

while True:

    response = input("Type Rock, Paper, Scissors or q to quit: ").title()
    print(response)

    if response in rps_entries:

        print('Will continue game')

    elif response == 'Q':

        print("Goodbye")
        break

Something simple to conceptualize and consider.

1 Like

Hey,

As it happens I’ve got it working now. Print statements at the end just needed an extra de-indent. After eyeballing it a bit more I saw this. I figured it out by minimising the game - taking out a couple of elif statements just so I could see things clearer. The intention was not for the game to run correctly per se - but so the user inputs worked. Now they do. Capitals were previously accounted for by .lower() thrown in to the code.

Testing comes in all sorts of forms then. If a low-tech way can be employed then all the better I guess. I know with bigger projects the test frameworks will be needed much more.

Thanks for your inputs

2 Likes