Project 2: Generics and Unit Testing

Due: Monday, 15 Aug 2011, at 23:59:59 PST

Overview

In Project 1 you implemented a non-generic doubly-linked list. In Project 2 you will be "generifying" your linked-list. You will also be developing unit tests to ensure that your linked-list implementation works correctly. Your unit tests will also be used to test the linked-lists of your classmates to make sure they work properly as well. (We may also throw in some faulty and non-faulty linked-list implelmentations of our own.)

Part 1: 3 points

Generify your DoublyLinkedList12 from P1 so that it accepts objects of type T, not object. your new, generic, DoublyLinkedList12 must implement the generic List12 interface (its Javadoc can also be viewed here). Since List12 extends Iterable, your linked-list must support the iterator() method, which should return an object of type Iterator.

Your source file DoublyLinkedList12.java should clearly contain your full name and student ID in a comment at the very top of the file.

Grading

Your generic linked-list will be graded using an automatic script and possibly also manually inspected.

Part 2: 5 points

Using the junit 4.8.2 (note the version number!) unit testing framework (download it here), you will develop a set of unit tests with which to verify the correctness of your linked-list. You should create one single Java file, DoublyLinkedList12Tester.java, which contains all the tests. You can use this "tester" to test your (generic) DoublyLinkedList12 implementation from Part 1 of this assignment. However, your tests must also detect bugs in someone else's (possibly faulty) linked-list implementation. We will test multiple implementations of DoublyLinkedList12 -- some faulty, and some correct -- using your test code. You must use junit-4.8.2 -- you cannot use an earlier version of junit.

Black-box versus white-box testing

In P2, you will be conducting black-box testing of the generic version of DoublyLinkedList12. This means that your test routines should not "peer" into the internal workings (e.g., instance variables) of the DoublyLinkedList12 class you are testing. If you do so (despite this warning), then you will likely get 0 credit because your test code will not compile against someone else's DoublyLinkedList12 implementation (which may use different instance variables). Note that this contrasts with white-box testing, where you do inspect the "inner workings" of a class. For the sake of clarity: In your test code in P2, you should test the DoublyLinkedList12 implementation using only the methods specified in the public List12 interface.

Getting started

Create a file called DoublyLinkedList12Tester.java and import the following classes:

import java.util.*;
import org.junit.*;
import org.junit.Assert.*;

Then, create a class called DoublyLinkedList12Tester which contains a number of unit test methods. To mark a method as being a "unit test", you should annotate the method using the @Test keyword. Here's an example:

@Test public void testAddOneElement () { // Pretty weak test!
final DoublyLinkedList12<String> list = new DoublyLinkedList12<String>();
list.add("test");
Assert.assertEquals(list.size(), 1);
}

Note: your test methods should not return anything, nor should they print out anything. Instead, each of your test methods should include at least one call to an "assert" static method in the Assert class to verify that a specific condition is true.

Compiling your code

To compile your test code, first copy the junit-4.8.2.jar file into your current directory. Assuming DoublyLinkedList12.java and DoublyLinkedList12Tester.java are also in the current directory, run: javac -cp .:junit-4.8.2.jar DoublyLinkedList12Tester.java.

Running your code

To run your tester, you will invoke junit's unit testing framework -- it will scan your DoublyLinkedList12Tester.class file for all methods annotated with the @Test keyword (using something called "reflection"), and it will run each of these tests. At the command line, run java -cp .:junit-4.8.2.jar org.junit.runner.JUnitCore DoublyLinkedList12Tester.

Grading

We will be grading according to the following scheme: On any DoublyLinkedList12 implementation that is correct, all of your unit tests in DoublyLinkedList12Tester must pass. On any DoublyLinkedList12 implementation that is incorrect, at least one of your unit tests must fail. Now, suppose that we submit N different implementations of DoublyLinkedList12 to your tester. For every implementation that your tester "classifies correctly" (correctly passes, or correctly fails), your "testing score" S will be increased by 1 point. However, for every implementation that your tester "classifies incorrectly" (incorrectly passes, or incorrectly fails), your testing score S will be decreased by one point. After all N tests are complete, your score will be normalized (as S/N*5) so that the maximum is 5 points. If, however, S is negative (because your tester incorrectly classified more implementations than it correctly classified), then you will receive 0 points (instead of a negative score) for Part 2 of the assignment.

Your tester will be graded using an automatic script and possibly also manually inspected.

Submission

Submit your work using the bundleP2 script in the directory containing your (generic) DoublyLinkedList12.java and DoublyLinkedList12Tester.java files. Make sure you are logged on to ieng6.ucsd.edu using your CSE 12-specific account. As always, make sure to submit before the deadline -- the script will show you (or anyone else) no mercy!