Kotlinlearncs.online LogoJava
Return to List

Test Writing: PingPonger Class

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a public class PingPonger. A PingPonger is in one of two states: ping or pong. You should provide a constructor accepting a String argument that sets the initial state. If the passed String is "ping", the initial state is ping. If the passed String is "pong", the initial state is pong. If the passed String is not ping or pong, you should throw an IllegalArgumentException.

Once the PingPonger has been created, the user should call pong if the state is ping and ping if the state is pong. ping takes no arguments and returns true. pong takes no arguments and returns false. If ping or pong is called out of order, you should throw an IllegalStateException.

Here's an example:

Test Design Challenge

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

  • Provide a public class named TestPingPonger with a single non-private class 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 Kotlin's assert or check methods