diff --git a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java index ee7ec0fbe9e99712db8ef33c952e9df22d1ba738..2e1ec7e24c9782ccad68d8b3b68d2ddc65c7d76a 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();