テストプログラム

TDUList5Test


package tdu;
import static org.junit.Assert.*;
import org.junit.Test;
public class TDUList5Test {
	@Test
	public void testSet0() {
		TDUList5 list = new TDUList5();
		list.add("abc");
		list.add(null);
		list.add("ghi");
		list.set(1,"456");
		list.set(0,"123");
		list.set(2,"789");
		assertEquals("789",list.get(2));
		assertEquals("123",list.get(0));
		assertEquals("456",list.get(1));
	}
}

TDUListIterator5Test


package tdu;
import static org.junit.Assert.*;
import org.junit.Test;
import java.util.ListIterator;
public class TDUListIterator5Test {
	@Test
	public void testLast() {
		Node<String> node = new Node<String>();
		TDUListIterator5 listIterator = new TDUListIterator5(node,0);
		assertNull(listIterator.last);
		listIterator.add("abc");
		assertNull(listIterator.last);
		listIterator = new TDUListIterator5(node,0);
		assertEquals("abc",listIterator.next());
		assertEquals("abc",listIterator.last.get());
		listIterator.add("def");
		assertNull(listIterator.last);	
	}
	@Test(expected=IllegalStateException.class)
	public void testSet0() {
		TDUListIterator5 listIterator = new TDUListIterator5(new Node<String>(),0);
		listIterator.set("xyz");
	}
	@Test(expected=IllegalStateException.class)
	public void testSet1() {
		TDUList5 list = new TDUList5();
		list.add("abc");
		ListIterator<String> listIterator =  list.listIterator(0);
		assertEquals("abc",listIterator.next());
		listIterator.add("def");
		listIterator.set("xyz");
	}
	@Test
	public void testSet2() {
		Node<String> n0 = new Node<String>();
		Node<String> n3 = new Node<String>("abc");
		Node<String> n2 = new Node<String>(null);
		Node<String> n1 = new Node<String>("ghi");
		n1.next=n0;
		n2.next=n1;
		n3.next=n2;
		TDUListIterator5 listIterator = new TDUListIterator5(n3,0);
		assertEquals("abc",listIterator.next());
		listIterator.set("123");
		assertEquals(null,listIterator.next());
		listIterator.set("456");
		assertEquals("ghi",listIterator.next());
		listIterator.set("789");
		assertEquals("123",n3.get());
		assertEquals("456",n2.get());
		assertEquals("789",n1.get());
	}

}