Kotlinlearncs.online LogoJava
Return to List

Test Writing: Even Odd Flip

Created By: Geoffrey Challen
/ Version: 2024.7.0

Create a public class EvenOddFlip. It should provide a single constructor accepting an int, which sets the initial state of the instance.

Provide two instance methods.

  1. setValue accepts a single int and updates the stored value. You should assert that the value passed to setValue is even if the current value is odd, and odd if the current value is even.
  2. isEven retrieves whether the current saved value is even.

Here's an example of how your class should work:

Test Design Challenge

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

  • Provide a public class named TestEvenOddFlip 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 Java's assert method