X1201: Test indexOf of a List

Use this interface definition to solve this exercise.

public interface ListADT<E> {
   // returns number of elements stored
   public int size();

   // removes all elements
   public void clear();

   // return true if list is empty, false otherwise
   public boolean isEmpty();

   // adds e at the end of the list
   public boolean add(E e);

   // returns true if o is in the list, false otherwise
   public boolean contains(Object o);

   // returns the object at index, returns null if
   // index is invalid
   public E get(int index);

   // returns the index of o if it exists, -1 otherwise
   public int indexOf(Object o);
}

Write a test method to test the indexOf() of List<String>. The test infrastructure has an variable named instance of type List<String>. When your test is run, this object has just been allocated. Write at least 3 asserts to test the indexOf() of the instance object. Add some objects, check the indexOf() the objects added as well as some objects not in the list.

Your Answer:

Feedback

Your feedback will appear here when you check your answer.