CPTR 124 Fundamentals of Programming


In this lab you will modify the NonemptyList class from Chapter 16 and develop some JUnit tests to test the list classes.


  1. Teams

    You are encouraged to work with a partner for this lab. You and your partner should begin thinking about the problems and begin writing the code before lab time.

  2. Preparing your working folder

    Make a subfolder named Lab9 within your H:\cptr124 folder. Copy the List, EmptyList, and NonemptyList classes from Chapter 16 into your Lab9 folder. (You can also get the code we did in class from the usual class code repository.)

  3. Part 1: Augmenting the NonemptyList class.

    Modify the NonemptyList class from Chapter 16. Override the equals() method that it currently simply inherits from java.lang.Object. Your equals() method should check for logical equality; that is, two lists are considered equal if they contain elements in the same positions that are logically equal. Your method should use the equals() methods of the individual elements of the lists. In particular, you should not use the == operator anywhere within the equals() method of NonemptyList.

  4. Part 2: Planning your tests.

    Devise a set of unit tests that can be used to verify the correctness (or at least reveal errors) of both list classes, EmptyList and your modified NonemptyList. Each test should focus on a specific aspect of the functionality of list objects. Be as comprehensive as you can. You goal is to attempt to detect as many errors as you can.

    Produce a word-processed document that outlines the purpose of each test. Write what you are attempting to accomplish with each test, not how the test will be performed. This document will be reviewed and suggestions for improvement may be made. Once your test plan is approved, you may proceed with Part 3.

  5. Part 3: Implementing your tests.

    Implement your test plans in a JUnit test suite. Intentionally (but temporarily) inject some errors into your EmptyList and NonemptyList classes to ensure that your test cases are doing their jobs properly.

    In order to do this part you need to put junit.jar into working folder. This jar file is available at http://perl.cs.southern.edu/repository/Misc/.

  6. Check out

    Revise your test plan document to include the name of the JUnit test method that implements the test in the plan. Your finished test code will be evaluated to see if it faithfully implements your test plan. When approved, you should submit printouts of your NonemptyList class and JUnit test class. Be sure your name and your partner(s) names are included on the printout.