CPE 102 Program 6a - Tests for the BasicLinkedList class

Ground Rules

No collaboration is allowed on this program assignment. Your program must be an individual and original effort. Except for any situations explicitly identified in this assignment, if any, you may only receive help from your instructor or the tutors provided by the Computer Science Department. See the Syllabus for the significant consequences for disallowed collaboration and/or plagiarism.

Due Date and Submission Instructions

Submit the following file(s) on one of the CSL servers using handin as follows:

    File(s): BasicLinkedListTest.java, BasicList.java, BasicListIterator.java, and a minimal version of BasicLinkedList.java
    touser: eaugusti
    assignment/subdirectory: 102-program06a

Objectives
  1. More practice applying the TDD process (Test Driven Development).
Orientation

You will be practicing the TDD process by developing SUnit tests for a class that represents a simple link-based list ADT (abstract data type). If, after reading he specifications, you are unsure how a method should behave you should try it using the Java Standard Library LinkedList class - your BasicLinkedList is expected to behave in exactly the same way.

Specification
  1. Your source code must meet the Programming Guidelines.

  2. Read about Test Driven Development (TDD), as necessary, to reorient yourself to the process you are about to embark on.
  3. Write a mimimal implementation of class and interfaces specified in the Program 6b assignment.

  1. In a class called BasicLinkedListTest write SUnit tests (the class you wrote in Program 1a) for each of the public methods of the BasicLinkedList class including the constructors and iterators.

    1. Testing in any Object Oriented language has the special challenge that the instance variables of an object are often private. Private instance variables are inaccessable to code outside the class which means the testing code cannot access them directly.The testing code must, instead, use the public methods of the class to perform the testing. The best practice is to use the same small set of methods to verify the results of all tests. To that end, you are strongly encouraged to use the following methods to verify the behavior of methods that modify the list:
      1. add()
      2. get()
      3. size()
    1. You must use SampleTest.java as the starting point for your test class. Use the save-as feature of your browser (or wget/curl if you are a cool kid), not cut-and-paste, to obtain a copy of SampleTest.java

      1. You must to rename SampleTest.java as BasicLinkedListTest.java
      2. You must change the name of the class from SampleTest to BasicLinkedListTest.
      3. Do not write or use constructors in the test class - they will not be called when grading your tests.
      4. Do not use any instance variables test class - they can not be accessed by the static test methods you will be writing.
      5. Do not modify the main of the test class - it will not be called when I grade your tests.
      6. You should write separate test methods for each method of the class you are testing.
    2. At a minimum you must write the following number of tests (you may write more). Think carefully about methods that change the contents of the list - you must verify that the list's state is correct after such calls.

      1. NOTE: When testing for expected exceptions you should use the following pattern so that you are credited for the test:
                    try
                    {
                       // Put your test code here...

                       // Followed by this code...
                       // This code will only run if your test does not result in the expected
                       // exception being thrown. It's purpose is to updated your test counts.
                       SUnit.fail();

                    }
                    catch(ExpectedExceptionTypeHere ref)
                    {
                      
// This will run if the expected exception is through during the test in
                       // the try-block above and will update your test counts correctly.

                       SUnit.assertTrue(true);
                    }

      1. BasicLinkedList(): 1 test (1 call to an SUnit method to verify the size of the list).
      2. add(int index, E element): 5 tests (11 calls to SUnit, 2 for exceptions and 9 for successful adds (calls to size and gets for each element after each add)).
      3. add(E element): 3 tests (9 calls to SUnit (size and gets for each element after each add)).
      4. basicListIterator():
        1. hasNext(): 3 tests (3 calls to SUnit (empty list, non-empty list, and the end of non-empty list).
        2. next(): 5 tests (5 calls to SUnit; 2 for exceptions (beginning of empty list and the end of a non-empty list) and 3 for successfull calls).
        3. remove(): 1 test (1 call to SUnit for exception).
        4. hasPrevious(): 3 tests (3 calls to SUnit (empty list, non-empty list, and the beginning of non-empty list).
        5. previous(): 5 test ( 5 calls to SUnit; 2 for exceptions (beginning of empty list and the beginning of non-empty list) and 3 for successfull calls).
      5. clear(): 2 tests (2 calls to SUnit, the size in two different scenarios).
      6. contains(E element): 2 tests (2 calls to SUnit, a true and a false case).
      7. get(int index): 3 tests (5 calls to SUnit, 2 for exceptions, 3 for successful gets (beginning, middle, and end).
      8. indexOf(E element): 2 tests (2 calls to SUnit, 1 for an exception, 1 for a successful find).
      9. iterator():
        1. hasNext(): 3 tests (3 calls to SUnit (empty list, non-empty list, and the end of non-empty list).
        2. next(): 5 tests (5 calls to SUnit; 2 for exceptions (beginning of empty list and the end of a non-empty list) and 3 for successfull calls).
        3. remove(): 1 test (1 call to SUnit for exception).
      10. remove(int index): 5 tests (8 calls to SUnit, 2 for exceptions, 6 for successful removes (get and size) at 3 well thoughtout locations).
      11. set(int index, E element): 5 tests (8 calls to SUnit, 2 for exceptions, 6 for successful sets (get and size) at 3 well thoughtout locations).
      12. size(): 0 tests - behavior verified in both constructors, both add methods, the remove method, and the set method.
Grading
  1. All of your non-boolean tests must report an error when compiled and run with a minimal implementation of the BasicLinkedList class.

  2. Some of your boolean tests must report an error (all of your true-tests or all of your false-tests for a method depending on what the minimal implementation returns).

  3. All of your tests must not report an error when compiled and run with a correct implementation of the BasicLinkedList class. You may not have a correct implementation when this assignment is due so develop them carefully. If you would like to see if your tests work with a correct implementation you could substitute BasicLinkedList and BasicListIterator with LinkedList and ListIterator from the Java Standard Library - just be sure to change you code back to using BasicLinkedList and BasicListIterator before handing it in!

Program courtesy of Kurt Mammen.