-
Notifications
You must be signed in to change notification settings - Fork 2
/
DequeDriver.java
162 lines (147 loc) · 5.31 KB
/
DequeDriver.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
TheMarkering - Jack Cruse, Sasha Fomina, Daniel Ju
APCS2 pd4
HW29 -- Stress is the Best
2017-04-05
*/
import java.util.Iterator;
public class DequeDriver {
public static void main(String [] args){
//tests add() and poll()
Deque<String> test = new DequeDLL<String>();
//System.out.println("Upon initialization: size = " + test.size());
/* Alternatively, addLast()
System.out.println("\nTesting add()...");
//adding elements until capacity of 5
System.out.println("one: " + test.add("one"));
System.out.println("two: " + test.add("two"));
System.out.println("three: " + test.add("three"));
System.out.println("four: " + test.add("four"));
System.out.println("five: " + test.add("five"));
System.out.println("six: " + test.add("six") + "-past capacity");
*/
System.out.println("\nTesting addLast()...");
//adding elements until capacity of 5
test.addLast("one");
test.addLast("two");
test.addLast("three");
test.addLast("four");
test.addLast("five");
test.addLast("six");
System.out.println(test + "\n");
System.out.println("\nTesting toString()...");
System.out.println(test);
// System.out.println("size = " + test.size());
/*
System.out.println("\nTesting contains()...");
System.out.println(test.contains("one"));
System.out.println(test.contains("two"));
System.out.println(test.contains("three"));
System.out.println(test.contains("four"));
System.out.println(test.contains("five"));
//"six" does not exist
System.out.println(test.contains("six") + "- 'six' was never inserted");
*/
/* Alternatively test pollLast()
System.out.println("\nTesting poll()...");
//removes elements one by one
System.out.println(test.poll());
System.out.println(test.poll());
System.out.println(test.poll());
System.out.println(test.poll());
System.out.println(test.poll());
//polling an empty Dequeue
System.out.println(test.poll() + "-list empty");
*/
System.out.println("\nTesting removeLast()...");
System.out.println( test );
//removes elements one by one
test.removeLast();
System.out.println(test);
test.removeLast();
System.out.println( test);
test.removeLast() ;
System.out.println(test);
test.removeLast();
//System.out.println(test.removeLast() + " - " + test);
//removeLasting an empty Dequeue
//System.out.println(test.removeLast() + "-list empty");
// System.out.println("\nEnd of test 1\n");
//Deque<String> test2 = new DequeDLL<String>();
//System.out.println("Upon initialization: size = " + test2.size());
System.out.println("\nTesting addFirst()...");
test.addFirst("zero");
test.addLast("neg 1");
test.addLast("neg 2");
test.addLast("neg 3");
test.addLast("neg 4");
test.addLast("neg 5");
System.out.print("After addition " + test);
/*
System.out.println("\nTesting addFirst()...");
System.out.println("one: " + test2.addFirst("one"));
System.out.println("two: " + test2.addFirst("two"));
System.out.println("three: " + test2.addFirst("three"));
System.out.println("four: " + test2.addFirst("four"));
System.out.println("five: " + test2.addFirst("five"));
//should not work, as the Dequeue is to capacity
System.out.println("six: " + test2.addFirst("six"));
*/
//System.out.println("\nTesting toString()...");
//System.out.println(test2);
//elements are backwards, as they were added to the front (stacky?)
// System.out.println("size = " + test2.size());
/*
System.out.println("\nTesting contains()...");
System.out.println(test2.contains("one"));
System.out.println(test2.contains("two"));
System.out.println(test2.contains("three"));
System.out.println(test2.contains("four"));
System.out.println(test2.contains("five"));
System.out.println(test2.contains("six") + "-never inserted 'six'");
*/
System.out.println("\nTesting removeFirst()...");
test.removeFirst();
System.out.println(test);
test.removeFirst();
System.out.println(test);
test.removeFirst();
System.out.println(test);
test.removeFirst();
System.out.println(test);
//System.out.println(test2.removeLast());
//System.out.println(test2.removeLast() + "-past capacity");
/*
System.out.println("value added: " + test2.addLast( "to" ) );
System.out.println("value added: " + test2.addFirst( "like" ) );
System.out.println("value added: " + test2.addLast( "sleep" ) );
System.out.println("value added: " + test2.addFirst( "I" ) );
System.out.println( test2 );
*/
/*
System.out.println(test.removeFirst() + " - " + test);
System.out.println(test.removeFirst() + " - " + test);
System.out.println(test.removeFirst() + " - " + test);
System.out.println(test.removeFirst() + " - " + test);
*/
//UNCOMMENT TO MAKE SURE IT THROWS PROPER ERROR
//removing from an empty deque
Deque<String> test2 = new DequeDLL<String>();
test2.removeFirst();
test.removeLast();
/*
System.out.println("value added: " + test2.addLast( "to" ) );
System.out.println("value added: " + test2.addFirst( "like" ) );
System.out.println("value added: " + test2.addLast( "sleep" ) );
System.out.println("value added: " + test2.addFirst( "I" ) );
System.out.println( test2 );
*/
/*
Iterator<String> itr = test2.iterator();
while ( itr.hasNext() )
{
System.out.println( itr.next() );
}
*/
}//end main
}//end driver