-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestArrayDequeGold.java
45 lines (39 loc) · 1.7 KB
/
TestArrayDequeGold.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
import static org.junit.Assert.*;
import org.junit.Test;
public class TestArrayDequeGold {
@Test
public void testDeque() {
//@Source Joshua Hug
StudentArrayDeque<Integer> sad1 = new StudentArrayDeque<>();
ArrayDequeSolution<Integer> correct1 = new ArrayDequeSolution<>();
int counter = 0;
String errorMessage = "";
while (true) {
double random = StdRandom.uniform();
if (random >= 0 && random < 0.25) {
if (!(sad1.size() == 0) && !(correct1.size() == 0)) {
Integer studentNum = sad1.removeFirst();
Integer correctNum = correct1.removeFirst();
errorMessage = errorMessage + "removeFirst(" + studentNum + ")\n";
assertEquals(errorMessage, studentNum, correctNum);
}
} else if (random >= .25 && random < .5) {
if (!(sad1.size() == 0) && !(correct1.size() == 0)) {
Integer studentNum = sad1.removeLast();
Integer correctNum = correct1.removeLast();
errorMessage = errorMessage + "removeLast(" + studentNum + ")\n";
assertEquals(errorMessage, studentNum, correctNum);
}
} else if (random >= .5 && random < .75) {
sad1.addFirst(counter);
correct1.addFirst(counter);
errorMessage = errorMessage + "addFirst(" + counter + ")\n";
} else {
sad1.addLast(counter);
correct1.addLast(counter);
errorMessage = errorMessage + "addLast(" + counter + ")\n";
}
counter += 1;
}
}
}