Kotlinlearncs.online LogoJava
Return to List

Test Writing: Primes Switch Expression

Created By: Ellen Spertus
/ Version: 2024.1.0

Write a function determineStatus() that takes an int argument. If the value is 0 or 1, it should return "neither prime nor composite". If the value is 2, 3, 5, or 7, it should return "prime". If the value is 4, 6, 8, or 9, it should return "composite". If it is any other value, it should return "out of range". Use a switch expression.

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: