Kotlinlearncs.online LogoJava
Return to List

Test Writing: Course Equality

Created By: Geoffrey Challen
/ Version: 2020.9.0

Create a class named Course. Course should define a primary constructor that accepts three values: a String? (the department), a String? (the course number, and yes, this must be a String) and an Int (the enrollment). You are welcome to name these properties however you like, and they should be private. Your constructor should reject null departments and numbers and negative enrollments.

Define a single method named equals. Your equals method accepts an Any? as a single parameter. It should return true if the passed object is a Course and has the same values for the department and number, and false otherwise.

Test Design Challenge

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

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