Kotlinlearncs.online LogoJava
Return to List

Test Writing: Dog Is Older

Created By: Geoffrey Challen
/ Version: 2021.3.0

Create a class Dog that stores a single private Double age set by the primary constructor. (Reject negative ages using assert.) Dog should also provide a companion object with a single method named isOlder. isOlder should accept two Dog instances and return true if the first is older than the second, and false otherwise.

So here is how Dog should work:

Test Design Challenge

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

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