Kotlinlearncs.online LogoJava
Return to List

Test Writing: SimpleLinkedList find

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a public class FindLinkedList that extends SimpleLinkedList, which has an zero-argument constructor. Provide an instance method find that accepts an Any as a parameter and returns whether the object appears in the list. You can assume that the passed Any is not null, and that the list will not contain any null values.

As a reminder, our SimpleLinkedList is composed of a chain of Items, where Item is defined as an inner class on SimpleLinkedList:

The SimpleLinkedList class also has a start property that refers to the start of the list, or null if the list is empty. Note that the list that you are extending does not have a size field or a get method, meaning that you will need to walk the list to solve this problem. (That's the point!)

Test Design Challenge

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

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