@@ -74,7 +74,7 @@ private static IndexedPriorityQueue<Node> newNodePQ() {
7474 // ------------------------
7575
7676 @ Test
77- void testOfferPollWithIntegers_ComparableMode () {
77+ void testOfferPollWithIntegersComparableMode () {
7878 // cmp == null -> elements must be Comparable
7979 IndexedPriorityQueue <Integer > pq = new IndexedPriorityQueue <>();
8080 Assertions .assertTrue (pq .isEmpty ());
@@ -211,7 +211,7 @@ void testChangeKeyChoosesDirectionAutomatically() {
211211 }
212212
213213 @ Test
214- void testDirectMutationWithoutChangeKeyDoesNotReheap_ByDesign () {
214+ void testDirectMutationWithoutChangeKeyDoesNotReheapByDesign () {
215215 // Demonstrates the contract: do NOT mutate comparator fields directly.
216216 IndexedPriorityQueue <Node > pq = newNodePQ ();
217217 Node a = new Node ("A" , 5 );
@@ -237,7 +237,7 @@ void testDirectMutationWithoutChangeKeyDoesNotReheap_ByDesign() {
237237 // ------------------------
238238
239239 @ Test
240- void testDuplicateEqualsElementsAreSupported_IdentityMap () {
240+ void testDuplicateEqualsElementsAreSupportedIdentityMap () {
241241 IndexedPriorityQueue <NodeWithEquals > pq =
242242 new IndexedPriorityQueue <>(Comparator .comparingInt (n -> n .prio ));
243243
@@ -262,15 +262,15 @@ void testDuplicateEqualsElementsAreSupported_IdentityMap() {
262262 @ Test
263263 void testGrowByManyInserts () {
264264 IndexedPriorityQueue <Integer > pq = new IndexedPriorityQueue <>();
265- int N = 100 ; // beyond default capacity (11)
265+ int n = 100 ; // beyond default capacity (11)
266266
267- for (int i = N ; i >= 1 ; i --) {
267+ for (int i = n ; i >= 1 ; i --) {
268268 pq .offer (i );
269269 }
270270
271- Assertions .assertEquals (N , pq .size ());
271+ Assertions .assertEquals (n , pq .size ());
272272 // Ensure min-to-max order when polling
273- for (int expected = 1 ; expected <= N ; expected ++) {
273+ for (int expected = 1 ; expected <= n ; expected ++) {
274274 Integer v = pq .poll ();
275275 Assertions .assertEquals (expected , v );
276276 }
@@ -315,4 +315,46 @@ void testRemoveHeadAndMiddleAndTail() {
315315 Assertions .assertTrue (pq .isEmpty ());
316316 Assertions .assertNull (pq .peek ());
317317 }
318+
319+ // ------------------------
320+ // Error / edge cases for coverage
321+ // ------------------------
322+
323+ @ Test
324+ void testInvalidInitialCapacityThrows () {
325+ Assertions .assertThrows (
326+ IllegalArgumentException .class ,
327+ () -> new IndexedPriorityQueue <Integer >(0 , Comparator .naturalOrder ()));
328+ }
329+
330+ @ Test
331+ void testChangeKeyOnMissingElementThrows () {
332+ IndexedPriorityQueue <Node > pq = newNodePQ ();
333+ Node a = new Node ("A" , 10 );
334+
335+ Assertions .assertThrows (
336+ IllegalArgumentException .class ,
337+ () -> pq .changeKey (a , n -> n .prio = 5 ));
338+ }
339+
340+ @ Test
341+ void testDecreaseKeyOnMissingElementThrows () {
342+ IndexedPriorityQueue <Node > pq = newNodePQ ();
343+ Node a = new Node ("A" , 10 );
344+
345+ Assertions .assertThrows (
346+ IllegalArgumentException .class ,
347+ () -> pq .decreaseKey (a , n -> n .prio = 5 ));
348+ }
349+
350+ @ Test
351+ void testIncreaseKeyOnMissingElementThrows () {
352+ IndexedPriorityQueue <Node > pq = newNodePQ ();
353+ Node a = new Node ("A" , 10 );
354+
355+ Assertions .assertThrows (
356+ IllegalArgumentException .class ,
357+ () -> pq .increaseKey (a , n -> n .prio = 15 ));
358+ }
359+
318360}
0 commit comments