forked from ucsd-cse15l-w23/lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListTests.java
More file actions
55 lines (45 loc) · 1.19 KB
/
LinkedListTests.java
File metadata and controls
55 lines (45 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import static org.junit.Assert.*;
import org.junit.*;
public class LinkedListTests{
Node node3;
LinkedList list, list2;
@Before
public void setUp() throws Exception{
list = new LinkedList();
node3 = new Node(3, null);
Node node2 = new Node(2, node3);
Node node1 = new Node(1, node2);
list.root = node1;
list2 = new LinkedList();
}
@Test
public void testPrepend(){
list.prepend(0);
assertEquals("0 1 2 3 ", list.toString());
list2.prepend(0);
assertEquals("0 ", list2.toString());
}
@Test
public void testAppend(){
list.append(4);
list2.append(4);
assertEquals("1 2 3 4 ", list.toString());
assertEquals("4 ", list2.toString());
}
@Test
public void testFirst(){
assertEquals(1, list.first());
}
@Test
public void testLast(){
assertEquals(3, list.last());
assertEquals(3, list2.last());
}
@Test
public void testLength(){
assertEquals(3, list.length());
assertEquals(0, list2.length());
list2.root = node3;
assertEquals(1, list2.length());
}
}