5import static org.junit.Assert.*;
11 assertTrue(list.
empty());
17 assertEquals(list.
size(),0);
18 for (
int i=0;i<10;++i) {
20 assertEquals(list.
size(),i+1);
27 for (
int i=0;i<10;++i) {
29 assertEquals(list.
front().intValue(),i);
32 for (
int i=0;i<10;++i) {
33 assertTrue(list.
at(i)==n-1-i);
51 assertTrue(list.
at(i)==i+1);
54 assertTrue(list.
size()==8);
55 assertTrue(list.
front()==2);
56 assertTrue(list.
at(0)==2);
59 assertTrue(list.
size()==7);
60 assertTrue(list.
back()==8);
61 assertTrue(list.
at(list.
size()-1)==8);
63 assertTrue(list.
at(2)==4);
65 assertTrue(list.
size()==6);
66 assertTrue(list.
at(2)==5);
68 while (!list.
empty()) {
73 assertTrue(list.
empty());
76 assertTrue(list.
front().intValue()==1);
79 @Test(expected=IndexOutOfBoundsException.class)
86 @Test(expected=IndexOutOfBoundsException.class)
92 @Test(expected=IndexOutOfBoundsException.class)
98 @Test(expected=IndexOutOfBoundsException.class)
105 @Test(expected=IndexOutOfBoundsException.class)
110 @Test(expected=IndexOutOfBoundsException.class)
119 for (
int i=0;i<5;++i)
125 for (
int i=0;i<5;++i) {
126 assertTrue(ii.hasNext());
127 n=ii.next().intValue();
130 assertFalse(ii.hasNext());
133 for (Integer i : list) {
134 assertTrue(n==i.intValue());
139 list.insert_after(ii,-1);
140 assertTrue(ii.hasNext());
143 assertTrue(ii.hasNext());
146 assertTrue(ii.hasNext());
151 public static void main(String args[]) {
155 org.junit.runner.JUnitCore.main(
"aud.test.SListTest");
Implementation of a singly linked list.
void erase(int i)
erase entry at position i [O(n)]
T front()
retrieve first entry (must exist) [O(1)]
Iterator iterator()
get forward iterator
T at(int i)
retrieve i-th entry [O(n)]
void insert(int i, T obj)
insert new entry obj at position i [O(n)]
int size()
determine number of entries [O(n)]
void pop_front()
erase first entry (must exist) [O(1)]
void push_front(T obj)
insert entry at front of list [O(1)]
T back()
retrieve last entry (must exist) [O(n)]
void pop_back()
erase last entry (must exist) [O(n)]
boolean empty()
determine if list is empty [O(1)]
void push_back(T obj)
append entry obj at end of list [O(n)]
static void main(String args[])
void testInvalid_pop_front()
void testInvalid_pop_back()
AuD lecture: Data structures, algorithms, examples.