Commit 9546dec0 authored by winterbloom's avatar winterbloom
Browse files

Adds test for using increase/decrease key in the wrong direction, updates dependsOn

parent 78532aa7
1 merge request!1Updates
Showing with 22 additions and 3 deletions
+22 -3
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment