Kotlinlearncs.online LogoJava
Return to List

Test Writing: Game Tiebreaker Function

Created By: Geoffrey Challen
/ Version: 2021.8.0

Two players have completed a game. Write a method (or function) named whoWon to determine the winner!

whoWon receives three parameters in the following order: the score of the first player as an int, the score of the second player as an int, and whether the first player played first as a boolean.

If either player scored more points than the other, they are the winner! However, if both players tie, then the player that played second is the winner.

Return the result of the game as an int. You should return 1 if Player 1 won and 2 if Player 2 won.

If you have solved this problem previously without writing a method, you may reuse your old code! However, you may try to eliminate the winner variable that we used previously.

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: