Skip to content

Commit 334543f

Browse files
testing: improve test coverage PriorityQueuesTest (TheAlgorithms#6397)
testing: improve test coverage PriorityQueuesTest Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
1 parent d14e8a6 commit 334543f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,60 @@ void testPQExtra() {
5555
Assertions.assertEquals(myQueue.peek(), 2);
5656
Assertions.assertEquals(myQueue.getSize(), 1);
5757
}
58+
59+
@Test
60+
void testInsertUntilFull() {
61+
PriorityQueue pq = new PriorityQueue(3);
62+
pq.insert(1);
63+
pq.insert(4);
64+
pq.insert(2);
65+
Assertions.assertTrue(pq.isFull());
66+
Assertions.assertEquals(4, pq.peek());
67+
}
68+
69+
@Test
70+
void testRemoveFromEmpty() {
71+
PriorityQueue pq = new PriorityQueue(3);
72+
Assertions.assertThrows(RuntimeException.class, pq::remove);
73+
}
74+
75+
@Test
76+
void testInsertDuplicateValues() {
77+
PriorityQueue pq = new PriorityQueue(5);
78+
pq.insert(5);
79+
pq.insert(5);
80+
pq.insert(3);
81+
Assertions.assertEquals(5, pq.peek());
82+
pq.remove();
83+
Assertions.assertEquals(5, pq.peek());
84+
pq.remove();
85+
Assertions.assertEquals(3, pq.peek());
86+
}
87+
88+
@Test
89+
void testSizeAfterInsertAndRemove() {
90+
PriorityQueue pq = new PriorityQueue(4);
91+
Assertions.assertEquals(0, pq.getSize());
92+
pq.insert(2);
93+
Assertions.assertEquals(1, pq.getSize());
94+
pq.insert(10);
95+
Assertions.assertEquals(2, pq.getSize());
96+
pq.remove();
97+
Assertions.assertEquals(1, pq.getSize());
98+
pq.remove();
99+
Assertions.assertEquals(0, pq.getSize());
100+
}
101+
102+
@Test
103+
void testInsertAndRemoveAll() {
104+
PriorityQueue pq = new PriorityQueue(3);
105+
pq.insert(8);
106+
pq.insert(1);
107+
pq.insert(6);
108+
Assertions.assertTrue(pq.isFull());
109+
pq.remove();
110+
pq.remove();
111+
pq.remove();
112+
Assertions.assertTrue(pq.isEmpty());
113+
}
58114
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy