diff --git a/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java b/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java index 1a3b5aadebb2..e97fe091c556 100644 --- a/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java +++ b/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java @@ -55,4 +55,60 @@ void testPQExtra() { Assertions.assertEquals(myQueue.peek(), 2); Assertions.assertEquals(myQueue.getSize(), 1); } + + @Test + void testInsertUntilFull() { + PriorityQueue pq = new PriorityQueue(3); + pq.insert(1); + pq.insert(4); + pq.insert(2); + Assertions.assertTrue(pq.isFull()); + Assertions.assertEquals(4, pq.peek()); + } + + @Test + void testRemoveFromEmpty() { + PriorityQueue pq = new PriorityQueue(3); + Assertions.assertThrows(RuntimeException.class, pq::remove); + } + + @Test + void testInsertDuplicateValues() { + PriorityQueue pq = new PriorityQueue(5); + pq.insert(5); + pq.insert(5); + pq.insert(3); + Assertions.assertEquals(5, pq.peek()); + pq.remove(); + Assertions.assertEquals(5, pq.peek()); + pq.remove(); + Assertions.assertEquals(3, pq.peek()); + } + + @Test + void testSizeAfterInsertAndRemove() { + PriorityQueue pq = new PriorityQueue(4); + Assertions.assertEquals(0, pq.getSize()); + pq.insert(2); + Assertions.assertEquals(1, pq.getSize()); + pq.insert(10); + Assertions.assertEquals(2, pq.getSize()); + pq.remove(); + Assertions.assertEquals(1, pq.getSize()); + pq.remove(); + Assertions.assertEquals(0, pq.getSize()); + } + + @Test + void testInsertAndRemoveAll() { + PriorityQueue pq = new PriorityQueue(3); + pq.insert(8); + pq.insert(1); + pq.insert(6); + Assertions.assertTrue(pq.isFull()); + pq.remove(); + pq.remove(); + pq.remove(); + Assertions.assertTrue(pq.isEmpty()); + } } 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