From 27fc872edb64fa6ea632ef94fb3e98e17754c0da Mon Sep 17 00:00:00 2001 From: PuneetTri <43619937+PuneetTri@users.noreply.github.com> Date: Sun, 27 Nov 2022 17:26:16 +0530 Subject: [PATCH] Add JUnit tests for priority queue data structure (#3778) --- .../queues/PriorityQueuesTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java diff --git a/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java b/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java new file mode 100644 index 00000000..e5af3026 --- /dev/null +++ b/src/test/java/com/thealgorithms/datastructures/queues/PriorityQueuesTest.java @@ -0,0 +1,58 @@ +package com.thealgorithms.datastructures.queues; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class PriorityQueuesTest { + + @Test + void testPQInsertion() { + PriorityQueue myQueue = new PriorityQueue(4); + myQueue.insert(2); + Assertions.assertEquals(myQueue.peek(), 2); + + myQueue.insert(5); + myQueue.insert(3); + Assertions.assertEquals(myQueue.peek(), 5); + + myQueue.insert(10); + Assertions.assertEquals(myQueue.peek(), 10); + } + + @Test + void testPQDeletion() { + PriorityQueue myQueue = new PriorityQueue(4); + myQueue.insert(2); + myQueue.insert(5); + myQueue.insert(3); + myQueue.insert(10); + + myQueue.remove(); + Assertions.assertEquals(myQueue.peek(), 5); + myQueue.remove(); + myQueue.remove(); + Assertions.assertEquals(myQueue.peek(), 2); + } + + @Test + void testPQExtra() { + PriorityQueue myQueue = new PriorityQueue(4); + Assertions.assertEquals(myQueue.isEmpty(), true); + Assertions.assertEquals(myQueue.isFull(), false); + myQueue.insert(2); + myQueue.insert(5); + Assertions.assertEquals(myQueue.isFull(), false); + myQueue.insert(3); + myQueue.insert(10); + Assertions.assertEquals(myQueue.isEmpty(), false); + Assertions.assertEquals(myQueue.isFull(), true); + + myQueue.remove(); + Assertions.assertEquals(myQueue.getSize(), 3); + Assertions.assertEquals(myQueue.peek(), 5); + myQueue.remove(); + myQueue.remove(); + Assertions.assertEquals(myQueue.peek(), 2); + Assertions.assertEquals(myQueue.getSize(), 1); + } +}