本次代写是Java的一个作业

Goal

The goal of this assignment is to implement a Doubly Linked List, a List Iterator and create
JUnit tests to verify their proper operation and implementation. To implement the Doubly
Linked List, you will implement the List interface and additional methods. You will then develop
a ListIterator to traverse over the Doubly Linked List. You will use existing JUnit tests and also
write your own JUnit tests to test your implementation of a Doubly Linked List and the List
Iterator.

As you get started, please pay attention to the following:

  • Please read the ENTIRE write-up before getting started.
  • For this homework and all homework in CSE 12, you may not change any public
    class/method or variable names given in the write-up or starter code.

Getting Started

We strongly recommend that you work on EdStem, but if you choose to work on your own
machine, make sure your code runs correctly on EdStem, as that is where we will be testing it.
When you run ‘javac’ and ‘java’ make sure you are in the same directory where the files are
located. This is called your working directory. For this assignment, you will need to utilize the
.jar files in the ‘libs’ directory in the starter code. This will be similar to how you compiled and
executed in PA1.

How to compile and run the tester:

$ javac -cp ./libs/junit-4.12.jar:libs/hamcrest-core-1.3.jar:. MyLinkedList.java My
$ java -cp ./libs/junit-4.12.jar:libs/hamcrest-core-1.3.jar:. org.junit.runner.JUni

Part 1 – Understanding and Testing First

In this homework assignment you will be developing a Doubly Linked List as well as an Iterator
for this list. Of course, these data structures are already supported in the Java Collections
Framework (LinkedList and ListIterator). But as weʼve mentioned in class, implementing data
structures is one of the best ways to become a better programmer and to really understand
whatʼs going on “under the hood” .

1. First Understand what MyLinkedList and MyListIterator will do

In parts 2 and 3 youʼll be implementing the classes MyLinkedList and MyListIterator, but in this
part (Part 1) you will develop a tester that includes JUnit tests in order to test Javaʼs own
implementation of LinkedList and the methods supported in that class. Later, when you finish
Part 2 and Part 3, you will use this tester to test your own implementation of a Doubly Linked
List and your list iterator.

In order to write a good tester, you will need a deep understanding of how the classes and
methods you are testing are supposed to work. So before you start writing your tester, you
should read part 2 and part 3 in order to understand what your LinkedList and ListIterator
classes are supposed to do. You may refer to the documentation for LinkedList and
AbstractList.

2. MyLinkedListTester.java

Open the supplied file MyLinkedListTester.java. This is a starter file that defines a small
number of tests against MyLinkedList. Observe and check how each test is written and
what it tests for.

Feel free to add more tests, as the provided starter test is not comprehensive, and your
program will later be tested against our master test.

You should make sure to include tests to check that your method throws the correct
exceptions when they are expected to throw them. There are more sophisticated ways to
do this (feel free to investigate and use them), but the simple approach is to do the
following (from https://github.com/junit-team/junit4/wiki/Exception-testing):

@Test
public void testExceptionMessage() {
try {
new ArrayList<Object>().get(0);
fail(“Expected an IndexOutOfBoundsException to be thrown”);
} catch (IndexOutOfBoundsException anIooBException) {
assertThat(anIooBoundsException.getMessage(),
is(“Index: 0, Size: 0”));
}
}