テストプログラム

TDUList3Test


package tdu;
import static org.junit.Assert.*;
import org.junit.Test;
public class TDUList3Test {
	@Test
	public void testAdd() {
		TDUList3 list = new TDUList3();
		assertEquals(0,list.size());
		list.add("abc");
		assertEquals(1,list.size());
		list.add(null);
		assertEquals(2,list.size());
		list.add("ghi");
		assertEquals(3,list.size());
	}
}

TDUListIterator3Test


package tdu;
import static org.junit.Assert.*;
import org.junit.Test;
public class TDUListIterator3Test {
	private Node<String> getList(){
		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;
		return n3;
	}
	private Node<String> getEmptyList(){
		return new Node<String>();
	}
	@Test(expected=IndexOutOfBoundsException.class)
	public void testConstructor00(){
		assertNotNull(new TDUListIterator3(getEmptyList(),0));
		new TDUListIterator3(getEmptyList(),-1);
	}
	@Test(expected=IndexOutOfBoundsException.class)
	public void testConstructor01(){
		new TDUListIterator3(getEmptyList(),1);
	}
	@Test(expected=IndexOutOfBoundsException.class)
	public void testConstructor30(){
		new TDUListIterator3(getList(),-1);
	}
	@Test
	public void testConstructor3(){
		assertNotNull(new TDUListIterator3(getList(),0));
		assertNotNull(new TDUListIterator3(getList(),1));
		assertNotNull(new TDUListIterator3(getList(),2));
		assertNotNull(new TDUListIterator3(getList(),3));
	}
	@Test(expected=IndexOutOfBoundsException.class)
	public void testConstructor34(){
		new TDUListIterator3(getList(),4);
	}
	@Test
	public void testAdd1() {
		Node<String> node=getEmptyList();
		TDUListIterator3 listIterator = new TDUListIterator3(node,0);
		listIterator.add("xyz");
		listIterator.add("012");
		assertEquals("xyz",node.get());
		assertEquals("012",node.next.get());
	}
	@Test
	public void testAdd2() {
		Node<String> node=getList();
		TDUListIterator3 listIterator = new TDUListIterator3(node,1);
		listIterator.add("xyz");
		listIterator.add("012");
		assertEquals("abc",node.get());
		assertEquals("xyz",node.next.get());
		assertEquals("012",node.next.next.get());
		assertEquals(null,node.next.next.next.get());
		assertEquals("ghi",node.next.next.next.next.get());
	}
	@Test
	public void testAdd3() {
		Node<String> node=getList();
		TDUListIterator3 listIterator = new TDUListIterator3(node,3);
		listIterator.add("xyz");
		listIterator.add("012");
		assertEquals("abc",node.get());
		assertEquals(null,node.next.get());
		assertEquals("ghi",node.next.next.get());
		assertEquals("xyz",node.next.next.next.get());
		assertEquals("012",node.next.next.next.next.get());
	}
	@Test(expected=UnsupportedOperationException.class)
	public void removeTest(){
		TDUListIterator3 listIterator = new TDUListIterator3(getList(),0);
		listIterator.next();
		listIterator.remove();
	}
	@Test(expected=UnsupportedOperationException.class)
	public void setTest(){
		TDUListIterator3 listIterator = new TDUListIterator3(getList(),0);
		listIterator.next();
		listIterator.set("xyz");	
	}
}