Kotlinlearncs.online LogoJava
Return to List

Test Writing: Recursive Factorial

Created By: Geoffrey Challen
/ Version: 2020.11.0

Implement a method factorial that accepts a single Long and returns its factorial as a Long. You can reject negative arguments and ones greater than 20 by throwing an IllegalArgumentException.

You should submit a recursive solution. The factorial of 0 is 1, and this represents the base case. The factorial of n is n * the factorial of n - 1, and this represents the recursive step.

Test Design Challenge

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

  • Provide a public class named TestFactorial 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