CPE 102 Program 2a - Tests for the BasicArrayList 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.

Errata

    None so far - updates and corrections, if any, will show up here (be sure to refresh this page as necessary).

Due Date and Submission Instructions

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

    File(s): BasicArrayListTest.java, BasicList.java, and a minimal version of BasicArrayList.java

    touser: eaugusti

    assignment/subdirectory: 102-program02a

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 array-based list ADT (abstract data type).

Specification

  1. Your source code must meet the Programming Guidelines.

  2. Read about Test Driven Development (TDD) to orient yourself to the process you are about to embark on.
  3. Write the BasicList interface and a mimimal implementation of BasicArrayList class found in the Program 2b assignment. Recall that a minimal implementation allows you to develop and compile tests for a class's methods before attempting to write them correctly. The process of developinig the tests requires that you to understand what the methods are supposed to do before you write them - always good information to have! With the mimimal implementation you can compile and run your tests to verify that they do, in fact, report errors for methods that are known to be incorrect.Recall that a minimally implemented class has no instance variables and no logic except for the return statements necessary to satisfy the compiler. Where possible, choose return values that are always wrong (would never be returned by a correct version of the method) so that tests checking for correct behavior will always fail. When no always-wrong value is available then choose something clearly recognizable and remember to not write tests expecting that value to be returned as the correct result.

  4. In a class called BasicArrayListTest write SUnit tests (the class you wrote in Program 1a) for each of the public methods of the BasicArrayList class including the constructors.

    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 in your tests:
      1. add()
      2. get()
      3. size()
      4. capacity()
    1. You must use SampleTest.java as the starting point for your test class. Use the save-as feature of your browser, not cut-and-paste, to obtain a copy of SampleTest.java

      1. You must to rename SampleTest.java as BasicArrayListTest.java
      2. You must change the name of the class from SampleTest to BasicArrayListTest.
      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. BasicArrayList(): 1 test (2 calls to SUnit methods, one to verify the size of the list and one to verify the capacity of the list).
      2. BasicArrayList(int capacity): 3 tests (6 calls to SUnit methods - see details in default constructor).
      3. add(int index, Object o): 5 tests (8 calls to SUnit, 2 for exceptions, 6 for successful adds (get and size) at 3 well thoughtout locations).
      4. add(Object o): 3 tests (6 calls to SUnit, get and size after each add).
      5. capacity(): 2 tests (4 calls to SUnit, the capacity just before and just after at least two growth points).
      6. clear(): 2 tests (4 calls to SUnit, the size and capacity in two different scenarios).
      7. contains(Object o): 2 tests (2 calls to SUnit, a true and a false case).
      8. get(int index): 3 tests (5 calls to SUnit, 2 for exceptions, 3 for successful gets).
      9. indexOf(Object o): 2 tests (2 calls to SUnit, 1 for an exception, 1 for a successful find).
      10. remove(int index): 5 tests (11 calls to SUnit, 2 for exceptions, 9 for successful removes (the value returned, the size of the list, and the new value at the index) at 3 well thoughtout locations).
      11. set(int index): 5 tests (11 calls to SUnit, 2 for exceptions, 9 for successful sets (the value returned, the size of the list, and the new value at the index) at 3 well thoughtout locations).
      12. size(): 0 tests - behavior verified in both constructors, both add methods, the remove method, and the set method.
      13. trimToSize(): 2 tests (4 calls to SUnit, size and capacity in two different scenarios).
Grading
  1. All of your non-boolean tests must report an error when compiled and run with a minimal implementation of the BasicArrayList 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 BasicArrayList class. You may not have a correct implementation when this is due so develop them carefully!

Program courtesy of Kurt Mammen.