Skip to content

Commit 5fb62ad

Browse files
committed
feat: added unit test for monotonic queue
1 parent d44c968 commit 5fb62ad

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package test.dataStructures.queue;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import src.dataStructures.queue.MonotonicQueue;
6+
public class MonotonicQueueTest {
7+
@Test
8+
public void testEmpty() {
9+
MonotonicQueue<Integer> q = new MonotonicQueue<>();
10+
Assert.assertEquals(true, q.isEmpty());
11+
Assert.assertEquals(null, q.max());
12+
Assert.assertEquals(null, q.pop());
13+
}
14+
15+
@Test
16+
public void testMax() {
17+
MonotonicQueue<Integer> q = new MonotonicQueue<>();
18+
q.push(2);
19+
Assert.assertEquals("2", q.max().toString());
20+
q.push(7);
21+
Assert.assertEquals("7", q.max().toString());
22+
q.push(1);
23+
Assert.assertEquals("7", q.max().toString());
24+
q.push(7);
25+
Assert.assertEquals("7", q.max().toString());
26+
q.push(5);
27+
Assert.assertEquals("7", q.max().toString());
28+
q.push(4);
29+
Assert.assertEquals("7", q.max().toString());
30+
q.push(3);
31+
q.push(2);
32+
q.push(5);
33+
Assert.assertEquals("7", q.max().toString());
34+
}
35+
36+
@Test
37+
public void testPop() {
38+
MonotonicQueue<Integer> q = new MonotonicQueue<>();
39+
q.push(2);
40+
q.push(7);
41+
q.push(1);
42+
q.push(7);
43+
q.push(5);
44+
q.push(4);
45+
q.push(3);
46+
q.push(2);
47+
q.push(5);
48+
q.push(2);
49+
50+
Assert.assertEquals("7", q.pop().toString());
51+
Assert.assertEquals("7", q.pop().toString());
52+
Assert.assertEquals("5", q.pop().toString());
53+
q.pop();
54+
Assert.assertEquals("2", q.pop().toString());
55+
Assert.assertEquals(null, q.pop());
56+
}
57+
}

0 commit comments

Comments
 (0)