The JUnit test I wrote did not "weed out" all the bad shallowCopy code. The whole idea of a shallow copy was to make you write code that "copied" the structure (as the arrays were copied in my array implementations). Here you had to write code that copied the linked list. When I was looking at some code for shallowCopy in LinkedStack, I frequently saw something like public OrderedCollection<E> shallowCopy() { LinkedStack<E> answer = new LinkedStack<E>(); answer.top = this.top; answer.objectCount = this.objectCount; return answer; } Note that the top references in both LinkedStack objects SHARE the same list. One is not a COPY of the other. Queues and PriorityQueues had similar wrong code. Unfortunately, this passed my JUnit test. It is unfortunate for you because you might not have learned how to write the correct code. It is unfortunately for me that by the rules of the course, I gave everyone credit for this since it passed my test but.... 1) This shows that just because something passes a JUnit test it doesn't mean it is "right". The test could be wrong or insufficient to weed out all buggy solutions. I wanted you to copy a structure, but my test did not distinguish between sharing and copying data inside the objects. 2) I have updated all the JUnit tests so that shallowCopy also does the following (this is in the JUnit test for priority queues) pq.addAll(new ArrayList<String>(standardAddAll)); PriorityQueue<String> pq2 = (PriorityQueue<String>) pq.shallowCopy(); Iterator<String> i = pq.iterator(); i.next(); i.next(); i.remove();
assertArrayEquals("shallowCopy failed: copy changed", makeStringArray("abcdefg"),pq2.toArray()); Here, it loads up pq with some values, makes a copy and stores it into pq2, then it mutates the inside of the pq data, and checks to make sure pq2 hasn't been mutated (if it has, the data structures were SHARED, NOT COPIED). If you write code like that shown above, the test will fail. 3) You should redownload the start project folder and get/use this new TestPriorityQueue.java and TestMap.java files. When we test your code for Programming Assignment #3 we will be using this updated test, so that is the one you should be using for testing purposes.