-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathExtensiveStackTest.java
More file actions
43 lines (39 loc) · 1.24 KB
/
ExtensiveStackTest.java
File metadata and controls
43 lines (39 loc) · 1.24 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
package ssj.algorithm.collections;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Created by shenshijun on 15/2/4.
*/
public class ExtensiveStackTest {
@Test
public void testStack() {
ExtensiveStack<Integer> int_stack = new ExtensiveStack<>();
assertTrue(int_stack.isEmpty());
for (int i = 0; i < 100; i++) {
int_stack.push(i);
}
assertEquals(int_stack.size(), 100);
assertTrue(int_stack.head().equals(99));
for (int i = 99; i >= 0; i--) {
assertTrue(int_stack.pop().equals(i));
}
assertTrue(int_stack.isEmpty());
}
@Test
public void testStackMinMax() {
ExtensiveStack<Integer> int_stack = new ExtensiveStack<>();
assertTrue(int_stack.isEmpty());
for (int i = 0; i < 100; i++) {
int random_int = (int) (Math.random() * 100);
int_stack.push(random_int);
}
System.out.println(int_stack);
for (int i = 99; i >= 0; i--) {
System.out.println(int_stack.max());
System.out.println(int_stack.min());
int_stack.pop();
}
assertTrue(int_stack.isEmpty());
}
}