Kotlinlearncs.online LogoJava
Return to List

Test Writing: Rock Paper Scissors

Created By: Giovanni Pastor
/ Version: 2023.8.0

Let's play rock-paper-scissors! Create a method name findWinner that accepts two int arguments: the first is my pick, the second is yours. The arguments will both between 0 and 2, inclusive, and correspond in the following way to rock, paper, and scissors:

  • 0: rock
  • 1: paper
  • 2: scissors

You can learn more about this game here. However, as a brief summary: scissors beats paper, paper beats rock, and rock beats scissors. If both players pick the same value, a tie occurs and the game continues.

Based on the values passed to findWinner, if I won return "I win!", if you won return "You win!", and if the round is a tie return "Play again!".

Note that there are ways to solve this problem without checking all possible combinations, and even more clever ways that utilize modular arithmetic.

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Java's assert method

Related Lessons

Stuck? You may find these lessons helpful: