-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomizedQueuetest.java
101 lines (83 loc) · 3.07 KB
/
RandomizedQueuetest.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
import edu.princeton.cs.algs4.StdOut;
public class RandomizedQueuetest {
public RandomizedQueuetest() {
StdOut.println("Methods tests");
methodtests();
StdOut.println("Exceptions tests");
exceptionstests();
}
public static void main(String[] args) {
new RandomizedQueuetest();
}
private void methodtests() {
try { //constructor
RandomizedQueue<Integer> item = new RandomizedQueue<Integer>();
StdOut.println("size: " + item.size());
StdOut.println("isEmpty: " + item.isEmpty());
for (Integer temp : item)
StdOut.println(temp);
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
StdOut.println("constructor: tested");
}
try { //enqueue
RandomizedQueue<Integer> item = new RandomizedQueue<Integer>();
for (int i = 0; i < 5; i++)
item.enqueue(i);
StdOut.println("size: " + item.size());
StdOut.println("isEmpty: " + item.isEmpty());
StdOut.println("Iterator 1:");
for (Integer temp : item){
StdOut.print(temp);
StdOut.print(',');
StdOut.println(' ');
}
StdOut.println("Iterator 2:");
for (Integer temp : item){
StdOut.print(temp);
StdOut.print(',');
StdOut.println(' ');
}
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
StdOut.println("enqueue, iteratable tested");
}
try { //dequeue
RandomizedQueue<Integer> item = new RandomizedQueue<Integer>();
item.enqueue(1);
StdOut.println("size: " + item.size());
StdOut.println("isEmpty: " + item.isEmpty());
StdOut.println(item.sample());
StdOut.println("size: " + item.size());
StdOut.println("isEmpty: " + item.isEmpty());
for (Integer temp : item)
StdOut.println(temp);
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
StdOut.println("dequeue: tested");
}
try { //sample
RandomizedQueue<Integer> item = new RandomizedQueue<Integer>();
for (int i = 0; i < 5; i++)
item.enqueue(i);
StdOut.println("size: " + item.size());
StdOut.println("isEmpty: " + item.isEmpty());
StdOut.println("Sampling: " + item.sample());
StdOut.println("size: " + item.size());
StdOut.println("isEmpty: " + item.isEmpty());
} catch (Exception ex) {
ex.printStackTrace();
}
finally {
StdOut.println("sample: tested");
}
}
private void exceptionstests() {
}
}