-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver.java
114 lines (105 loc) · 4.11 KB
/
Driver.java
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
public class Driver {
public static void main(String[] args) {
System.out.println("---------TESTING MYLINKEDLIST ---------");
System.out.println();
System.out.println("---- Testing toString() / add(value) / size() ----");
System.out.println();
MyLinkedList list = new MyLinkedList();
System.out.println("Empty List should print []: " + list);
System.out.println("List size should be 0: " + list.size());
System.out.println("Adding the value 0 should print true: " + list.add(0));
System.out.println("List should now be [0]: " + list);
System.out.println("List size should now be 1: " + list.size());
for (int x = 1; x < 10; x++){
list.add(x);
}
System.out.println("Adding values up to 10, list should be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: " + list);
System.out.println("List size should now be 10: " + list.size());
for (int x = 0; x < 1000; x++) {
list.add(x);
}
System.out.println("Adding 1000 values to list, size should be 1010: " + list.size());
System.out.println();
System.out.println();
System.out.println("---- Testing get(index) ----");
System.out.println();
list = new MyLinkedList();
for (int x = 0; x < 10; x++){
list.add(x);
}
System.out.println("Current list: " + list);
System.out.println("Get first index should print 1: " + list.get(1));
System.out.print("Get -1th index, should print an error: ");
try {
list.get(-1);
}
catch (IndexOutOfBoundsException e) {
System.out.println(e);
}
System.out.println();
System.out.println();
System.out.println("---- Testing set(index, value) ----");
System.out.println();
System.out.println("Current list: " + list);
System.out.println("Set 3rd index to 10 should print 3: " + list.set(3, 10));
System.out.println("Current list: " + list);
System.out.print("Set -1th index, should print an error: ");
try {
list.set(-1, 0);
}
catch (IndexOutOfBoundsException e) {
System.out.println(e);
}
for (int x = 0; x < 10; x++) {
list.set(x, x+1);
}
System.out.println("Setting every index of list with a loop, should be a list of 1-10 inclusive: " + list);
System.out.println();
System.out.println();
System.out.println("---- Testing contains and indexOf ----");
System.out.println();
System.out.println("list.contains(6) should print true: " + list.contains(6));
System.out.println("list.contains(70) should print false: " + list.contains(70));
System.out.println("list.indexOf(4) should print 3: " + list.indexOf(4));
System.out.println("list.indexOf(50) should print -1: " + list.indexOf(50));
System.out.println();
System.out.println();
System.out.println("---- Testing add(index, value) ----");
System.out.println();
System.out.println("Current list: " + list);
System.out.print("Add to -1th index, should print an error: ");
try {
list.add(-1, 0);
}
catch (IndexOutOfBoundsException e) {
System.out.println(e);
}
list.add(0, 0);
System.out.println("Add 0 to the 0th index: " + list);
list.add(10, 11);
System.out.println("Add 11 to the 10th index: " + list);
System.out.println();
System.out.println();
System.out.println("---- Testing remove methods ----");
System.out.println();
System.out.println("Current list: " + list);
System.out.println("Remove 0th index should print 0: " + list.remove(0));
System.out.println("Current list: " + list);
System.out.print("Removing -1th index, should print an error: ");
try {
list.remove(-1);
}
catch (IndexOutOfBoundsException e) {
System.out.println(e);
}
Integer num = 11;
System.out.println("Removing by value, trying to remove 11, should print true: " + list.remove(num));
System.out.println("Current list: " + list);
num = 100;
System.out.println("Trying to remove value 100, should print false: " + list.remove(num));
System.out.println("Current list: " + list);
System.out.println();
System.out.println();
System.out.println("--------- END OF TEST ----------");
}
}