Kotlinlearncs.online LogoJava
Return to List

Test Writing: Math Course Inheritance

Created By: Pranav Narayanan
/ Version: 2024.10.0

Write a class MathCourse which inherits from the existing class Course:

open class Course(val code: String?, val title: String?)

MathCourse should have an additional String field area, which is the branch of math that course pertains to. This value should be read-only. MathCourse's default constructor should accept parameters for the code, title, and area in that order.

MathCourse should also override toString() so that it returns a String of the format: "(code): (title) is in the (area) branch of math."

Test Design Challenge

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

  • Provide a public class named TestMathCourse 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
Report a Problem

Attribution must link to this page: https://www.learncs.online/testtesting/kotlin/math-course-inheritance/[email protected]