From 9546dec007c2b09f5ab7f4adb2f8b4532cb9ff2a Mon Sep 17 00:00:00 2001 From: winterbloom <23458874+winterbloom@users.noreply.github.com> Date: Fri, 17 Feb 2023 22:36:34 -0800 Subject: [PATCH] Adds test for using increase/decrease key in the wrong direction, updates dependsOn --- .../cs2/datastructures/MinFourHeapTests.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java index ee7ec0f..2e1ec7e 100644 --- a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java +++ b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java @@ -96,7 +96,7 @@ public class MinFourHeapTests { @Tag("C") @Order(3) @DisplayName("Attempting to modify the priority of a nonexistent element throws an exception") - @TestDescription("This test checks that if an element doesn't exist in the heap, you're implementation " + + @TestDescription("This test checks that if an element doesn't exist in the heap, your implementation " + "should not be able to call increaseKey and decreaseKey on such element.") @TestHint("Make sure you are throwing an exception for nonexistent elements in increaseKey and decreaseKey") @DependsOn({"increaseKey", "decreaseKey"}) @@ -111,6 +111,25 @@ public class MinFourHeapTests { }); } + @Test + @Tag("C") + @Order(3) + @DisplayName("Calling increaseKey with a lower priority or decreaseKey with a higher priority throws an exception") + @TestDescription("This test checks that increaseKey and decreaseKey only accept the arguments they should.") + @TestHint("Make sure you are throwing an exception when increaseKey is asked to decrease a key's priority, " + + "and vice versa for decreaseKey.") + @DependsOn({"increaseKey", "decreaseKey"}) + public void testChangeKeyWrongWay() { + MinFourHeap<Integer> heap = new MinFourHeap<>(); + heap.enqueue(new IPriorityQueue.PQElement<>(10, 10)); + assertThrows(IllegalArgumentException.class, () -> { + heap.increaseKey(new IPriorityQueue.PQElement<>(10, 9)); + }); + assertThrows(IllegalArgumentException.class, () -> { + heap.decreaseKey(new IPriorityQueue.PQElement<>(10, 11)); + }); + } + @Test @Tag("C") @Order(4) @@ -298,7 +317,7 @@ public class MinFourHeapTests { @TestHint("Make sure that all these methods exist (i.e. you have written a percolateDown (or equiv. name) method and findSmallestChild method) and that you are accounting for:\n" + "1. Cases where some or all of the children are null and/or out of bounds\n" + "2. Cases where all children have a higher priority than their parent, so no swapping should occur") - @DependsOn({"enqueue", "size", "increaseKey", "decreaseKey", "data (field)"}) + @DependsOn({"enqueue", "size", "dequeue", "increaseKey", "decreaseKey", "data (field)"}) @CsvSource({"100, 30000, 15000", "42, 10000, 5000"}) public void stressTestIncreaseDecrease(int seed, int size, int numToReplace) { MinFourHeap<Integer> heap = new MinFourHeap<>(); @@ -360,7 +379,7 @@ public class MinFourHeapTests { @TestHint("Make sure that all these methods exist (i.e. you have written a percolateDown (or equiv. name) method and findSmallestChild method) and that you are accounting for:\n" + "1. Cases where some or all of the children are null and/or out of bounds\n" + "2. Cases where all children have a higher priority than their parent, so no swapping should occur") - @DependsOn({"enqueue", "dequeue", "size", "data (field)"}) + @DependsOn({"enqueue", "dequeue", "size", "data (field)", "keyToIndexMap (field)"}) public void stressTestEnqueueDequeue(int seed, int size) { MinFourHeap<Integer> heap = new MinFourHeap<>(); Comparator<Integer> c = new IntegerComparator(); -- GitLab