From b3113f6417f395605ac7261942982f196247f18f Mon Sep 17 00:00:00 2001
From: ashahidu <ashahidu@caltech.edu>
Date: Thu, 22 Oct 2020 17:25:10 -0700
Subject: [PATCH 1/6] Tests for project 6

---
 .../cs2/interfaces/IPriorityQueue.java        |   4 +-
 .../cs2/datastructures/HeapTester.java        | 105 ++++++++++++------
 .../cs2/datastructures/NGramMapTests.java     |  24 ++--
 tests/edu/caltech/cs2/sorts/SortTester.java   |  22 ++--
 4 files changed, 97 insertions(+), 58 deletions(-)

diff --git a/src/edu/caltech/cs2/interfaces/IPriorityQueue.java b/src/edu/caltech/cs2/interfaces/IPriorityQueue.java
index a2ea84a..46f8738 100644
--- a/src/edu/caltech/cs2/interfaces/IPriorityQueue.java
+++ b/src/edu/caltech/cs2/interfaces/IPriorityQueue.java
@@ -8,9 +8,9 @@ package edu.caltech.cs2.interfaces;
 public interface IPriorityQueue<E> extends IQueue<IPriorityQueue.PQElement<E>> {
     public static class PQElement<E> {
         public final E data;
-        public final int priority;
+        public final double priority;
 
-        public PQElement(E data, int priority) {
+        public PQElement(E data, double priority) {
             this.data = data;
             this.priority = priority;
         }
diff --git a/tests/edu/caltech/cs2/datastructures/HeapTester.java b/tests/edu/caltech/cs2/datastructures/HeapTester.java
index a7ada1b..d3755f8 100644
--- a/tests/edu/caltech/cs2/datastructures/HeapTester.java
+++ b/tests/edu/caltech/cs2/datastructures/HeapTester.java
@@ -5,7 +5,10 @@ import edu.caltech.cs2.helpers.Reflection;
 
 import java.util.*;
 import java.util.ArrayList;
+import java.util.stream.Collectors;
 
+import edu.caltech.cs2.interfaces.ICollection;
+import edu.caltech.cs2.interfaces.IDictionary;
 import edu.caltech.cs2.interfaces.IPriorityQueue;
 import edu.caltech.cs2.misc.IntegerComparator;
 import org.junit.jupiter.api.*;
@@ -26,18 +29,12 @@ public class HeapTester {
         Inspection.assertNoImportsOf(STRING_SOURCE, regexps);
         Inspection.assertNoUsageOf(STRING_SOURCE, regexps);
     }
+
     @Test
     @Tag("C")
     public void testPublicInterface() {
-        Reflection.assertPublicInterface(MinFourHeap.class, List.of(
-                "enqueue",
-                "dequeue",
-                "iterator",
-                "decreaseKey",
-                "increaseKey",
-                "peek",
-                "size"
-        ));
+        Reflection.assertPublicInterface(MinFourHeap.class,
+                List.of("enqueue", "dequeue", "iterator", "decreaseKey", "increaseKey", "peek", "size"));
     }
 
     @Test
@@ -91,9 +88,16 @@ public class HeapTester {
             assertEquals(i + 1, heap.size());
 
             IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
-            for(int j = 0; j < heap.size(); j++) {
+            for (int j = 0; j < heap.size(); j++) {
                 assertEquals(step_by_step.get(i).toArray()[j], heap_data[j].data);
             }
+
+            // Make sure keyToIndexMap is updated correctly
+            IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
+                    heap);
+            for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
+                assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
+            }
         }
     }
 
@@ -110,6 +114,15 @@ public class HeapTester {
         }
         for (int i = 0; i < reference.size(); i++) {
             assertEquals(reference.remove(), heap.dequeue().data);
+
+            // Check keyToIndexMap
+            IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+            IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
+                    heap);
+            for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
+                assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
+            }
+
             assertEquals(reference.size(), heap.size());
         }
 
@@ -117,9 +130,7 @@ public class HeapTester {
 
     @Tag("C")
     @ParameterizedTest(name = "Stress test enqueue and dequeue.")
-    @CsvSource({
-            "100, 3000", "42, 1000"
-    })
+    @CsvSource({ "100, 30000", "42, 10000" })
     public void stressTestAddRemove(int seed, int size) {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         Comparator<Integer> c = new IntegerComparator();
@@ -132,10 +143,35 @@ public class HeapTester {
             }
             reference.add(num);
             assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(num, num)));
-            assertEquals(heap.size(), reference.size());
+
+            // Check at intervals to save computation
+            if (i % 499 == 0) {
+                IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+                IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
+                        heap);
+                for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
+                    assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
+                }
+            }
+
+            assertEquals(reference.size(), heap.size());
         }
         while (heap.size() != 0) {
-            assertEquals(heap.dequeue().data, reference.remove());
+            assertEquals(reference.remove(), heap.dequeue().data);
+
+            if (heap.size() % 499 == 0) {
+                IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+                IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
+                        heap);
+                for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
+                    if (heap_data[entry.value] == null) {
+                        // End of dequeue process
+                        assertTrue(heap.size() <= 2, "Heap contains null value");
+                        continue;
+                    }
+                    assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
+                }
+            }
         }
     }
 
@@ -148,16 +184,16 @@ public class HeapTester {
         for (int i = 0; i < values.size(); i++) {
             assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))));
         }
-        Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
+        Integer[] correctHeapData = { -100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70 };
         IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
-        for(int j = 0; j < heap.size(); j++) {
+        for (int j = 0; j < heap.size(); j++) {
             assertEquals(correctHeapData[j], heap_data[j].data);
         }
         heap.increaseKey(new IPriorityQueue.PQElement<>(-100, 100));
-        Integer[] correctHeapAfterIncrease = {-84, -4, 2, 3, -2, 9, 7, 1, 100, 19, 70};
+        Integer[] correctHeapAfterIncrease = { -84, -4, 2, 3, -2, 9, 7, 1, 100, 19, 70 };
         heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int i = 0; i < heap.size(); i++) {
-           assertEquals(correctHeapAfterIncrease[i], heap_data[i].priority);
+            assertEquals((double) correctHeapAfterIncrease[i], (double) heap_data[i].priority);
         }
     }
 
@@ -169,24 +205,22 @@ public class HeapTester {
         for (int i = 0; i < values.size(); i++) {
             assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))));
         }
-        Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
+        Integer[] correctHeapData = { -100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70 };
         IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
-        for(int j = 0; j < heap.size(); j++) {
+        for (int j = 0; j < heap.size(); j++) {
             assertEquals(correctHeapData[j], heap_data[j].data);
         }
         heap.decreaseKey(new IPriorityQueue.PQElement<>(7, -105));
-        Integer[] correctHeapAfterDecrease = {-105, -100, 2, 3, -2, 9, -84, 1, -4, 19, 70};
+        Integer[] correctHeapAfterDecrease = { -105, -100, 2, 3, -2, 9, -84, 1, -4, 19, 70 };
         heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int i = 0; i < heap.size(); i++) {
-           assertEquals(correctHeapAfterDecrease[i], heap_data[i].priority);
+            assertEquals((double) correctHeapAfterDecrease[i], (double) heap_data[i].priority);
         }
     }
 
     @Tag("C")
     @ParameterizedTest(name = "Stress test increase/decrease key")
-    @CsvSource({
-            "100,  3000, 1500", "42, 1000, 500"
-    })
+    @CsvSource({ "100,  30000, 15000", "42, 10000, 5000" })
     public void stressTestIncreaseDecrease(int seed, int size, int numToReplace) {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         Comparator<Integer> c = new IntegerComparator();
@@ -210,15 +244,14 @@ public class HeapTester {
             }
             IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
             int idx = r.nextInt(heap.size());
-            Integer origKey = (Integer)heap_data[idx].data;
+            Integer origKey = (Integer) heap_data[idx].data;
             while (removed.contains(origKey)) {
                 idx = r.nextInt(heap.size());
-                origKey = (Integer)heap_data[idx].data;
+                origKey = (Integer) heap_data[idx].data;
             }
             if (newKey < origKey) {
                 heap.decreaseKey(new IPriorityQueue.PQElement(origKey, newKey));
-            }
-            else {
+            } else {
                 heap.increaseKey(new IPriorityQueue.PQElement(origKey, newKey));
             }
             assertEquals(reference.size(), heap.size());
@@ -227,11 +260,17 @@ public class HeapTester {
             reference.add(newKey);
             assertEquals(reference.size(), heap.size());
         }
-
-        while(!reference.isEmpty()) {
+        int i = 0;
+        while (!reference.isEmpty()) {
             Integer er = reference.remove();
             IPriorityQueue.PQElement mr = heap.dequeue();
-            assertEquals(er, mr.priority);
+            if (er != mr.priority) {
+                System.err.println(i);
+                System.err.println(reference.size());
+                System.err.println(heap.size());
+            }
+            assertEquals((double) er, mr.priority);
+            i++;
         }
 
     }
diff --git a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
index 854b89e..f73b0d1 100644
--- a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
+++ b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
@@ -25,7 +25,8 @@ public class NGramMapTests {
     @Tag("B")
     @Test
     public void testForInvalidClasses() {
-        List<String> regexps = List.of("java.util.(?!Iterator|function.Function|function.Supplier|Random|Scanner)", "java.lang.reflect", "java.io");
+        List<String> regexps = List.of("java.util.(?!Iterator|function.Function|function.Supplier|Random|Scanner)",
+                "java.lang.reflect", "java.io");
         Inspection.assertNoImportsOf(STRING_SOURCE, regexps);
         Inspection.assertNoUsageOf(STRING_SOURCE, regexps);
     }
@@ -39,13 +40,15 @@ public class NGramMapTests {
         Function<IDeque<Character>, IterableString> stringCollector = (IDeque<Character> x) -> {
             char[] chars = new char[x.size()];
             for (int i = 0; i < chars.length; i++) {
-               chars[i] = x.peekFront();
-               x.addBack(x.removeFront());
+                chars[i] = x.peekFront();
+                x.addBack(x.removeFront());
             }
             return new IterableString(new String(chars));
         };
-        IDictionary<NGram, IDictionary<IterableString, Integer>> newOuter = new ChainingHashDictionary<>(MoveToFrontDictionary::new);
-        Supplier<IDictionary<IterableString, Integer>> newInner = () -> new ChainingHashDictionary<>(MoveToFrontDictionary::new);
+        IDictionary<NGram, IDictionary<IterableString, Integer>> newOuter = new ChainingHashDictionary<>(
+                MoveToFrontDictionary::new);
+        Supplier<IDictionary<IterableString, Integer>> newInner = () -> new ChainingHashDictionary<>(
+                MoveToFrontDictionary::new);
         return new NGramMap(in, N, newOuter, newInner);
     }
 
@@ -95,8 +98,7 @@ public class NGramMapTests {
         for (int i = 0; i < items.length; i++) {
             if (items[i].data.equals("over")) {
                 assertEquals(1, items[i].priority);
-            }
-            else {
+            } else {
                 assertEquals("nonexistent", items[i].data);
                 assertEquals(1, items[i].priority);
             }
@@ -112,6 +114,11 @@ public class NGramMapTests {
         map.updateCount(new NGram("fox jumps"), "nonexistent");
         map.updateCount(new NGram("fox jumps"), "nonexistent");
 
+        // Check nonexistent behavior
+        String[] afterNull = map.getWordsAfter(new NGram("lol fake"), 1);
+        assertNotNull(afterNull, "getWordsAfter() returns a null value, not a String array");
+        assertEquals(0, afterNull.length);
+
         String[] afterQuick = map.getWordsAfter(new NGram("The quick"), 2);
         assertEquals(1, afterQuick.length);
         assertEquals("brown", afterQuick[0]);
@@ -120,5 +127,4 @@ public class NGramMapTests {
         assertEquals(2, afterJumps.length);
         assertEquals("nonexistent", afterJumps[0]);
         assertEquals("over", afterJumps[1]);
-    }
-}
+    }}
\ No newline at end of file
diff --git a/tests/edu/caltech/cs2/sorts/SortTester.java b/tests/edu/caltech/cs2/sorts/SortTester.java
index 91d7eb0..df19320 100644
--- a/tests/edu/caltech/cs2/sorts/SortTester.java
+++ b/tests/edu/caltech/cs2/sorts/SortTester.java
@@ -54,13 +54,9 @@ public class SortTester {
     @Tag("C")
     public void testZeroK() {
         Comparator<Integer> c = new IntegerComparator();
-        IPriorityQueue.PQElement[] array = {
-                new IPriorityQueue.PQElement(1, 1),
-                new IPriorityQueue.PQElement(2, 2),
-                new IPriorityQueue.PQElement(3, 3),
-                new IPriorityQueue.PQElement(4, 4),
-                new IPriorityQueue.PQElement(5, 5)
-        };
+        IPriorityQueue.PQElement[] array = { new IPriorityQueue.PQElement(1, 1), new IPriorityQueue.PQElement(2, 2),
+                new IPriorityQueue.PQElement(3, 3), new IPriorityQueue.PQElement(4, 4),
+                new IPriorityQueue.PQElement(5, 5) };
         TopKSort.sort(array, 0);
         Integer[] correct = new Integer[5];
         assertArrayEquals(correct, array);
@@ -68,16 +64,15 @@ public class SortTester {
 
     @Tag("C")
     @ParameterizedTest(name = "Stress test TopKSort: size: {1}, k: {2}")
-    @CsvSource({
-            "42, 3000, 2000", "15, 5000, 1235", "20, 1000, 50"
-    })
+    @CsvSource({ "42, 3000, 2000", "15, 5000, 1235", "20, 1000, 50" })
     public void stressTest(int seed, int size, int k) {
-        Comparator<IPriorityQueue.PQElement<Integer>> c = (x, y) -> Integer.compare(x.priority, y.priority);
+        Comparator<IPriorityQueue.PQElement<Integer>> c = (x, y) -> Double.compare(x.priority, y.priority);
         Random r = new Random(seed);
         Integer[] intarray = r.ints(size).boxed().toArray(Integer[]::new);
+        Double[] doublearray = Arrays.stream(intarray).map(Double::valueOf).toArray(Double[]::new);
         IPriorityQueue.PQElement[] array = new IPriorityQueue.PQElement[intarray.length];
         for (int i = 0; i < intarray.length; i++) {
-            array[i] = new IPriorityQueue.PQElement(intarray[i], intarray[i]);
+            array[i] = new IPriorityQueue.PQElement(intarray[i], doublearray[i]);
         }
         IPriorityQueue.PQElement<Integer>[] sortedArray = array.clone();
         Arrays.sort(sortedArray, c);
@@ -85,8 +80,7 @@ public class SortTester {
         for (int i = 0; i < correct.length; i++) {
             if (i < k) {
                 correct[i] = sortedArray[sortedArray.length - i - 1];
-            }
-            else {
+            } else {
                 correct[i] = null;
             }
         }
-- 
GitLab


From 9f59306e7fc9907c84bec83457eab120b9244dd8 Mon Sep 17 00:00:00 2001
From: Ethan Ordentlich <eordentl@Caltech.edu>
Date: Fri, 12 Feb 2021 21:51:34 -0800
Subject: [PATCH 2/6] Miscellaneous cleanup changes

---
 .idea/misc.xml                                |   2 +-
 .idea/workspace.xml                           | 253 ++++--------------
 src/edu/caltech/cs2/interfaces/IDeque.java    |   2 +-
 .../caltech/cs2/interfaces/IDictionary.java   |   6 +-
 src/edu/caltech/cs2/interfaces/IList.java     |   7 -
 src/edu/caltech/cs2/types/NGram.java          |   1 +
 ...{HeapTester.java => MinFourHeapTests.java} |  54 ++--
 .../cs2/datastructures/NGramMapTests.java     |   2 +-
 .../cs2/project06/SpellingCorrectorTests.java |   2 +-
 tests/edu/caltech/cs2/sorts/SortTester.java   |  26 +-
 10 files changed, 97 insertions(+), 258 deletions(-)
 delete mode 100644 src/edu/caltech/cs2/interfaces/IList.java
 rename tests/edu/caltech/cs2/datastructures/{HeapTester.java => MinFourHeapTests.java} (83%)

diff --git a/.idea/misc.xml b/.idea/misc.xml
index 8485616..dd4cca3 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11.0.5" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11.0.9" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
 </project>
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 828ccae..ac70327 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,100 +2,17 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="85b5a371-aaad-42bc-ba46-b3dd6c4e178b" name="Default Changelist" comment="">
-      <change beforePath="$PROJECT_DIR$/../../project01/project01-nbodysimulation" beforeDir="false" afterPath="$PROJECT_DIR$/../../project01/project01-nbodysimulation" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/../../project01/project01-nbodysimulation-solution" beforeDir="false" afterPath="$PROJECT_DIR$/../../project01/project01-nbodysimulation-solution" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/../../project01/project01-reference-solution" beforeDir="false" afterPath="$PROJECT_DIR$/../../project01/project01-reference-solution" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/../../project02/spec/spec.log" beforeDir="false" afterPath="$PROJECT_DIR$/../../project02/spec/spec.log" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/../../project02/spec/spec.pdf" beforeDir="false" afterPath="$PROJECT_DIR$/../../project02/spec/spec.pdf" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/../.idea/encodings.xml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../.idea/libraries/com_github_javaparser_javaparser_core_3_5_12.xml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../.idea/libraries/org_hamcrest_hamcrest_all_1_3.xml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../.idea/misc.xml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../.idea/modules.xml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../.idea/vcs.xml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/alice" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/best_corrections" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/dictionary.txt" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/edit_distance_test" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/possible_corrections/carefully_test" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/possible_corrections/conscious_test" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/possible_corrections/rear_test" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../data/possible_corrections/tied_test" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../lib/jsoup-1.11.3.jar" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/.idea/libraries/com_github_javaparser_javaparser_core_3_5_12.xml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/.idea/libraries/org_jsoup_jsoup_1_11_3.xml" beforeDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/.idea/project06-beaverchat.iml" beforeDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/data/reddit-small.corpus" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/project06-beaverchat.iml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../project06.iml" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../spec/LinkedList.sty" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../spec/mfcs.cls" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../spec/spec.aux" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../spec/spec.log" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../spec/spec.out" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../spec/spec.pdf" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../spec/spec.tex" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/Chat.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/IRCCodes.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/Main.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/ServerConnection.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/css/chat.css" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/css/login.css" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/html/chat.html" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/html/login.html" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/js/chat.js" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/beaverchat/js/login.js" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/AVLTreeDictionary.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/ArrayDeque.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/ArrayList.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/BSTDictionary.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/ChainingHashDictionary.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/CircularArrayFixedSizeQueue.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/IterableString.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/LinkedDeque.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/MinFourHeap.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/MoveToFrontDictionary.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/NGramMap.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/datastructures/TrieMap.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/ICollection.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/IDeque.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/IDictionary.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/IFixedSizeQueue.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/IList.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/IQueue.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/IStack.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/ITrieMap.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/interfaces/collections/IPriorityQueue.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/misc/CorrectionChoice.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/misc/IntegerComparator.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/misc/LargeValueFirstComparator.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/misc/WordReader.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/sorts/TopKSort.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/types/Item.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/edu/caltech/cs2/types/NGram.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/wordcorrector/AutoCompleteTrie.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/wordcorrector/SpellingCorrector.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../src/wordsuggestor/ParseFBMessages.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/datastructures/HeapTester.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/datastructures/NGramMapTests.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/CaptureSystemOutput.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/FileSource.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/FileSourceProvider.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/ImageFileSource.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/ImageFileSourceProvider.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/Images.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/Inspection.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/Reflection.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/helpers/RuntimeInstrumentation.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java" beforeDir="false" />
-      <change beforePath="$PROJECT_DIR$/../tests/edu/caltech/cs2/sorts/SortTester.java" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDeque.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDeque.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDictionary.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDictionary.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IList.java" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/types/NGram.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/types/NGram.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/HeapTester.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/NGramMapTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/NGramMapTests.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/sorts/SortTester.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/sorts/SortTester.java" afterDir="false" />
     </list>
-    <ignored path="$PROJECT_DIR$/out/" />
-    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
     <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -104,93 +21,6 @@
   <component name="CoverageDataManager">
     <SUITE FILE_PATH="coverage/project06$C_tests.ic" NAME="C tests Coverage Results" MODIFIED="1549453070890" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="idea" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" />
   </component>
-  <component name="FileEditorManager">
-    <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
-      <file pinned="false" current-in-tab="true">
-        <entry file="file://$PROJECT_DIR$/src/edu/caltech/cs2/types/NGram.java">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="-537">
-              <caret line="18" column="28" selection-start-line="18" selection-start-column="28" selection-end-line="18" selection-end-column="28" />
-              <folding>
-                <element signature="imports" expanded="true" />
-                <element signature="e#2017#2018#0" expanded="true" />
-                <element signature="e#2041#2042#0" expanded="true" />
-              </folding>
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/edu/caltech/cs2/sorts/TopKSort.java">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="360">
-              <caret line="16" selection-start-line="16" selection-end-line="16" />
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/edu/caltech/cs2/datastructures/MinFourHeap.java">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="192">
-              <caret line="8" selection-start-line="8" selection-end-line="8" />
-              <folding>
-                <element signature="imports" expanded="true" />
-                <element signature="e#829#830#0" expanded="true" />
-                <element signature="e#857#858#0" expanded="true" />
-                <element signature="e#908#909#0" expanded="true" />
-                <element signature="e#935#936#0" expanded="true" />
-                <element signature="e#983#984#0" expanded="true" />
-                <element signature="e#1010#1011#0" expanded="true" />
-                <element signature="e#1049#1050#0" expanded="true" />
-                <element signature="e#1073#1074#0" expanded="true" />
-                <element signature="e#1135#1136#0" expanded="true" />
-                <element signature="e#1162#1163#0" expanded="true" />
-              </folding>
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/edu/caltech/cs2/datastructures/NGramMap.java">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="567">
-              <caret line="124" selection-start-line="124" selection-end-line="124" />
-              <folding>
-                <element signature="imports" expanded="true" />
-                <element signature="e#3335#3336#0" expanded="true" />
-                <element signature="e#3362#3363#0" expanded="true" />
-                <element signature="e#3674#3675#0" expanded="true" />
-              </folding>
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/wordcorrector/SpellingCorrector.java">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="288">
-              <caret line="158" column="18" selection-start-line="158" selection-start-column="18" selection-end-line="158" selection-end-column="18" />
-              <folding>
-                <element signature="imports" expanded="true" />
-                <element signature="e#6589#6590#0" expanded="true" />
-                <element signature="e#6612#6613#0" expanded="true" />
-              </folding>
-            </state>
-          </provider>
-        </entry>
-      </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/src/beaverchat/Chat.java">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="1650">
-              <caret line="144" column="128" selection-start-line="144" selection-start-column="128" selection-end-line="144" selection-end-column="128" />
-            </state>
-          </provider>
-        </entry>
-      </file>
-    </leaf>
-  </component>
   <component name="FileTemplateManagerImpl">
     <option name="RECENT_TEMPLATES">
       <list>
@@ -242,6 +72,11 @@
     </dirStrings>
   </component>
   <component name="Git.Settings">
+    <option name="RECENT_BRANCH_BY_REPOSITORY">
+      <map>
+        <entry key="$PROJECT_DIR$" value="master" />
+      </map>
+    </option>
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
   </component>
   <component name="IdeDocumentHistory">
@@ -301,6 +136,9 @@
       </list>
     </option>
   </component>
+  <component name="MacroExpansionManager">
+    <option name="directoryName" value="sw29zy8v" />
+  </component>
   <component name="ProjectId" id="1XiXxxhZYHgsH5oUuCzgYftkYhR" />
   <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
   <component name="ProjectView">
@@ -450,6 +288,10 @@
       </pane>
     </panes>
   </component>
+  <component name="ProjectViewState">
+    <option name="hideEmptyMiddlePackages" value="true" />
+    <option name="showLibraryContents" value="true" />
+  </component>
   <component name="PropertiesComponent">
     <property name="Downloaded.Files.Path.Enabled" value="false" />
     <property name="Repository.Attach.Annotations" value="false" />
@@ -458,26 +300,19 @@
     <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1550120310864" />
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="Groovy JUnit" />
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.Groovy JUnit" value="groovy.util.GroovyTestCase" />
-    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
-    <property name="project.structure.last.edited" value="Libraries" />
+    <property name="last_opened_file_path" value="$PROJECT_DIR$/src/edu/caltech/cs2/datastructures" />
+    <property name="project.structure.last.edited" value="Project" />
     <property name="project.structure.proportion" value="0.15" />
-    <property name="project.structure.side.proportion" value="0.2" />
+    <property name="project.structure.side.proportion" value="0.39310345" />
     <property name="settings.editor.selected.configurable" value="project.propVCSSupport.Mappings" />
   </component>
   <component name="RecentsManager">
-    <key name="CreateTestDialog.RecentsKey">
-      <recent name="edu.caltech.cs2.datastructures" />
-    </key>
-    <key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
-      <recent name="" />
-      <recent name="edu.caltech.cs2.datastructures" />
-    </key>
     <key name="CopyFile.RECENT_KEYS">
+      <recent name="C:\Users\ethan\Documents\devel\project06\src\edu\caltech\cs2\datastructures" />
       <recent name="$PROJECT_DIR$/src/beaverchat" />
       <recent name="$PROJECT_DIR$/src" />
       <recent name="$PROJECT_DIR$/src/chatclient" />
       <recent name="$PROJECT_DIR$/src/wordcorrector" />
-      <recent name="$PROJECT_DIR$/src/edu/caltech/cs2/types" />
     </key>
     <key name="CreateTestDialog.Recents.Supers">
       <recent name="groovy.util.GroovyTestCase" />
@@ -488,18 +323,18 @@
       <recent name="$PROJECT_DIR$/src/beaverchat/css" />
       <recent name="$PROJECT_DIR$/data/possible_corrections" />
     </key>
-  </component>
-  <component name="RunDashboard">
-    <option name="ruleStates">
-      <list>
-        <RuleState>
-          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
-        </RuleState>
-        <RuleState>
-          <option name="name" value="StatusDashboardGroupingRule" />
-        </RuleState>
-      </list>
-    </option>
+    <key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
+      <recent name="" />
+      <recent name="edu.caltech.cs2.datastructures" />
+    </key>
+    <key name="CreateTestDialog.RecentsKey">
+      <recent name="edu.caltech.cs2.datastructures" />
+    </key>
+    <key name="CopyClassDialog.RECENTS_KEY">
+      <recent name="edu.caltech.cs2.datastructures" />
+      <recent name="edu.caltech.cs2.interfaces" />
+      <recent name="edu.caltech.cs2.types" />
+    </key>
   </component>
   <component name="RunManager" selected="JUnit.A Tests">
     <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
@@ -577,6 +412,7 @@
       </list>
     </recent_temporary>
   </component>
+  <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
   <component name="SvnConfiguration">
     <configuration />
   </component>
@@ -932,9 +768,20 @@
       <window_info anchor="right" id="Coverage" order="8" side_tool="true" weight="0.32977587" />
     </layout-to-restore>
   </component>
+  <component name="Vcs.Log.Tabs.Properties">
+    <option name="TAB_STATES">
+      <map>
+        <entry key="MAIN">
+          <value>
+            <State />
+          </value>
+        </entry>
+      </map>
+    </option>
+  </component>
   <component name="VcsManagerConfiguration">
     <ignored-roots>
-      <path value="$PROJECT_DIR$/../../.." />
+      <path value="$USER_HOME$" />
       <path value="$PROJECT_DIR$/../.." />
     </ignored-roots>
     <MESSAGE value="Work on spelling correction&#10;&#10;The spell check now computes all possible words of edit distance&#10;two. All that remains is choosing the most likely one." />
@@ -970,13 +817,11 @@
         <line-breakpoint type="java-line">
           <url>file://$PROJECT_DIR$/src/wordsuggestor/ParseFBMessages.java</url>
           <line>42</line>
-          <properties />
           <option name="timeStamp" value="67" />
         </line-breakpoint>
         <line-breakpoint type="java-line">
           <url>file://$PROJECT_DIR$/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java</url>
           <line>117</line>
-          <properties />
           <option name="timeStamp" value="92" />
         </line-breakpoint>
       </breakpoints>
diff --git a/src/edu/caltech/cs2/interfaces/IDeque.java b/src/edu/caltech/cs2/interfaces/IDeque.java
index 3b8f87a..4adba8f 100644
--- a/src/edu/caltech/cs2/interfaces/IDeque.java
+++ b/src/edu/caltech/cs2/interfaces/IDeque.java
@@ -24,7 +24,7 @@ public interface IDeque<E> extends ICollection<E> {
    */
   @Override
   default public void add(E e){
-    this.addFront(e);
+    this.addBack(e);
   }
 
   /**
diff --git a/src/edu/caltech/cs2/interfaces/IDictionary.java b/src/edu/caltech/cs2/interfaces/IDictionary.java
index 6465080..d04d3f3 100644
--- a/src/edu/caltech/cs2/interfaces/IDictionary.java
+++ b/src/edu/caltech/cs2/interfaces/IDictionary.java
@@ -1,5 +1,7 @@
 package edu.caltech.cs2.interfaces;
 
+import edu.caltech.cs2.datastructures.LinkedDeque;
+
 public interface IDictionary<K, V> extends Iterable<K> {
 
     public static class Entry<K, V> {
@@ -85,7 +87,7 @@ public interface IDictionary<K, V> extends Iterable<K> {
      *
      * @return a collection of the keys contained in this map
      */
-    public ICollection<K> keySet();
+    public ICollection<K> keys();
 
     /**
      * Returns a {@link ICollection} of the values contained in this map
@@ -97,7 +99,7 @@ public interface IDictionary<K, V> extends Iterable<K> {
 
     default public ICollection<Entry<K, V>> entrySet() {
         IDeque<Entry<K, V>> entries = new LinkedDeque<Entry<K,V>>();
-        for (K key : keySet()) {
+        for (K key : keys()) {
             entries.add(new Entry(key, this.get(key)));
         }
         return entries;
diff --git a/src/edu/caltech/cs2/interfaces/IList.java b/src/edu/caltech/cs2/interfaces/IList.java
deleted file mode 100644
index b91345d..0000000
--- a/src/edu/caltech/cs2/interfaces/IList.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package edu.caltech.cs2.interfaces;
-
-public interface IList<E> extends ICollection<E> {
-  public E get(int index);
-  public E set(int index, E element);
-  public E remove(int index);
-}
diff --git a/src/edu/caltech/cs2/types/NGram.java b/src/edu/caltech/cs2/types/NGram.java
index 24b324e..8b0b57c 100644
--- a/src/edu/caltech/cs2/types/NGram.java
+++ b/src/edu/caltech/cs2/types/NGram.java
@@ -1,5 +1,6 @@
 package edu.caltech.cs2.types;
 
+import edu.caltech.cs2.datastructures.LinkedDeque;
 import edu.caltech.cs2.interfaces.IDeque;
 
 import java.util.Iterator;
diff --git a/tests/edu/caltech/cs2/datastructures/HeapTester.java b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
similarity index 83%
rename from tests/edu/caltech/cs2/datastructures/HeapTester.java
rename to tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
index d3755f8..71bb6ee 100644
--- a/tests/edu/caltech/cs2/datastructures/HeapTester.java
+++ b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
@@ -17,7 +17,7 @@ import org.junit.jupiter.params.provider.CsvSource;
 
 import static org.junit.jupiter.api.Assertions.*;
 
-public class HeapTester {
+public class MinFourHeapTests {
     private static String STRING_SOURCE = "src/edu/caltech/cs2/datastructures/MinFourHeap.java";
 
     @Order(0)
@@ -41,9 +41,9 @@ public class HeapTester {
     @Tag("C")
     public void testDuplicateThrows() {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
-        heap.enqueue(new IPriorityQueue.PQElement(10, 10));
+        heap.enqueue(new IPriorityQueue.PQElement<>(10, 10));
         assertThrows(IllegalArgumentException.class, () -> {
-            heap.enqueue(new IPriorityQueue.PQElement(10, 10));
+            heap.enqueue(new IPriorityQueue.PQElement<>(10, 10));
         });
     }
 
@@ -87,7 +87,7 @@ public class HeapTester {
             assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))));
             assertEquals(i + 1, heap.size());
 
-            IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+            IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
             for (int j = 0; j < heap.size(); j++) {
                 assertEquals(step_by_step.get(i).toArray()[j], heap_data[j].data);
             }
@@ -116,7 +116,7 @@ public class HeapTester {
             assertEquals(reference.remove(), heap.dequeue().data);
 
             // Check keyToIndexMap
-            IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+            IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
             IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
                     heap);
             for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
@@ -130,7 +130,7 @@ public class HeapTester {
 
     @Tag("C")
     @ParameterizedTest(name = "Stress test enqueue and dequeue.")
-    @CsvSource({ "100, 30000", "42, 10000" })
+    @CsvSource({"100, 30000", "42, 10000"})
     public void stressTestAddRemove(int seed, int size) {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         Comparator<Integer> c = new IntegerComparator();
@@ -146,7 +146,7 @@ public class HeapTester {
 
             // Check at intervals to save computation
             if (i % 499 == 0) {
-                IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+                IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
                 IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
                         heap);
                 for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
@@ -160,7 +160,7 @@ public class HeapTester {
             assertEquals(reference.remove(), heap.dequeue().data);
 
             if (heap.size() % 499 == 0) {
-                IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+                IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
                 IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
                         heap);
                 for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
@@ -181,19 +181,19 @@ public class HeapTester {
         Comparator<Integer> c = new IntegerComparator();
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
-        for (int i = 0; i < values.size(); i++) {
-            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))));
+        for (Integer value : values) {
+            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
         }
-        Integer[] correctHeapData = { -100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70 };
-        IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
+        IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int j = 0; j < heap.size(); j++) {
             assertEquals(correctHeapData[j], heap_data[j].data);
         }
         heap.increaseKey(new IPriorityQueue.PQElement<>(-100, 100));
-        Integer[] correctHeapAfterIncrease = { -84, -4, 2, 3, -2, 9, 7, 1, 100, 19, 70 };
+        double[] correctHeapPrioritiesAfterIncrease = {-84, -4, 2, 3, -2, 9, 7, 1, 100, 19, 70};
         heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int i = 0; i < heap.size(); i++) {
-            assertEquals((double) correctHeapAfterIncrease[i], (double) heap_data[i].priority);
+            assertEquals(correctHeapPrioritiesAfterIncrease[i], (double) heap_data[i].priority);
         }
     }
 
@@ -202,25 +202,25 @@ public class HeapTester {
     public void testDecreaseKey() {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
-        for (int i = 0; i < values.size(); i++) {
-            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))));
+        for (Integer value : values) {
+            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
         }
-        Integer[] correctHeapData = { -100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70 };
-        IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
+        IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int j = 0; j < heap.size(); j++) {
             assertEquals(correctHeapData[j], heap_data[j].data);
         }
         heap.decreaseKey(new IPriorityQueue.PQElement<>(7, -105));
-        Integer[] correctHeapAfterDecrease = { -105, -100, 2, 3, -2, 9, -84, 1, -4, 19, 70 };
+        double[] correctHeapPrioritiesAfterDecrease = {-105, -100, 2, 3, -2, 9, -84, 1, -4, 19, 70};
         heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int i = 0; i < heap.size(); i++) {
-            assertEquals((double) correctHeapAfterDecrease[i], (double) heap_data[i].priority);
+            assertEquals(correctHeapPrioritiesAfterDecrease[i], heap_data[i].priority);
         }
     }
 
     @Tag("C")
     @ParameterizedTest(name = "Stress test increase/decrease key")
-    @CsvSource({ "100,  30000, 15000", "42, 10000, 5000" })
+    @CsvSource({"100, 30000, 15000", "42, 10000, 5000"})
     public void stressTestIncreaseDecrease(int seed, int size, int numToReplace) {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         Comparator<Integer> c = new IntegerComparator();
@@ -242,17 +242,17 @@ public class HeapTester {
             while (reference.contains(newKey) || removed.contains(newKey)) {
                 newKey = r.nextInt();
             }
-            IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+            IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
             int idx = r.nextInt(heap.size());
-            Integer origKey = (Integer) heap_data[idx].data;
+            Integer origKey = heap_data[idx].data;
             while (removed.contains(origKey)) {
                 idx = r.nextInt(heap.size());
-                origKey = (Integer) heap_data[idx].data;
+                origKey = heap_data[idx].data;
             }
             if (newKey < origKey) {
-                heap.decreaseKey(new IPriorityQueue.PQElement(origKey, newKey));
+                heap.decreaseKey(new IPriorityQueue.PQElement<>(origKey, newKey));
             } else {
-                heap.increaseKey(new IPriorityQueue.PQElement(origKey, newKey));
+                heap.increaseKey(new IPriorityQueue.PQElement<>(origKey, newKey));
             }
             assertEquals(reference.size(), heap.size());
             removed.add(origKey);
@@ -263,7 +263,7 @@ public class HeapTester {
         int i = 0;
         while (!reference.isEmpty()) {
             Integer er = reference.remove();
-            IPriorityQueue.PQElement mr = heap.dequeue();
+            IPriorityQueue.PQElement<Integer> mr = heap.dequeue();
             if (er != mr.priority) {
                 System.err.println(i);
                 System.err.println(reference.size());
diff --git a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
index f73b0d1..1b36aa2 100644
--- a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
+++ b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
@@ -36,7 +36,7 @@ public class NGramMapTests {
     Supplier<IDictionary<IterableString, Integer>> newInner;
 
     private NGramMap initNGramMap(Scanner in, int N) {
-        Function<IDeque<String>, NGram> ngramCollector = (IDeque<String> x) -> new NGram(x);
+        Function<IDeque<String>, NGram> ngramCollector = NGram::new;
         Function<IDeque<Character>, IterableString> stringCollector = (IDeque<Character> x) -> {
             char[] chars = new char[x.size()];
             for (int i = 0; i < chars.length; i++) {
diff --git a/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java b/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
index 38c37ce..20a6539 100644
--- a/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
+++ b/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
@@ -45,7 +45,7 @@ public class SpellingCorrectorTests {
     }
 
     private NGramMap initNGramMap(Scanner in, int N) {
-        Function<IDeque<String>, NGram> ngramCollector = (IDeque<String> x) -> new NGram(x);
+        Function<IDeque<String>, NGram> ngramCollector = NGram::new;
         Function<IDeque<Character>, IterableString> stringCollector = (IDeque<Character> x) -> {
             char[] chars = new char[x.size()];
             for (int i = 0; i < chars.length; i++) {
diff --git a/tests/edu/caltech/cs2/sorts/SortTester.java b/tests/edu/caltech/cs2/sorts/SortTester.java
index df19320..ad1f00e 100644
--- a/tests/edu/caltech/cs2/sorts/SortTester.java
+++ b/tests/edu/caltech/cs2/sorts/SortTester.java
@@ -2,7 +2,6 @@ package edu.caltech.cs2.sorts;
 
 import edu.caltech.cs2.helpers.Inspection;
 import edu.caltech.cs2.interfaces.IPriorityQueue;
-import edu.caltech.cs2.misc.IntegerComparator;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Order;
 import org.junit.jupiter.api.Tag;
@@ -34,8 +33,7 @@ public class SortTester {
     @Test
     @Tag("C")
     public void testEmptyArray() {
-        Comparator<Integer> c = new IntegerComparator();
-        IPriorityQueue.PQElement[] array = new IPriorityQueue.PQElement[0];
+        IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[0];
         TopKSort.sort(array, 1);
         assertArrayEquals(new Integer[0], array);
     }
@@ -43,8 +41,7 @@ public class SortTester {
     @Test
     @Tag("C")
     public void testNegativeK() {
-        Comparator<Integer> c = new IntegerComparator();
-        IPriorityQueue.PQElement[] array = new IPriorityQueue.PQElement[0];
+        IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[0];
         assertThrows(IllegalArgumentException.class, () -> {
             TopKSort.sort(array, -1);
         });
@@ -53,10 +50,11 @@ public class SortTester {
     @Test
     @Tag("C")
     public void testZeroK() {
-        Comparator<Integer> c = new IntegerComparator();
-        IPriorityQueue.PQElement[] array = { new IPriorityQueue.PQElement(1, 1), new IPriorityQueue.PQElement(2, 2),
-                new IPriorityQueue.PQElement(3, 3), new IPriorityQueue.PQElement(4, 4),
-                new IPriorityQueue.PQElement(5, 5) };
+        IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[]{
+                new IPriorityQueue.PQElement<>(1, 1), new IPriorityQueue.PQElement<>(2, 2),
+                new IPriorityQueue.PQElement<>(3, 3), new IPriorityQueue.PQElement<>(4, 4),
+                new IPriorityQueue.PQElement<>(5, 5)
+        };
         TopKSort.sort(array, 0);
         Integer[] correct = new Integer[5];
         assertArrayEquals(correct, array);
@@ -64,19 +62,19 @@ public class SortTester {
 
     @Tag("C")
     @ParameterizedTest(name = "Stress test TopKSort: size: {1}, k: {2}")
-    @CsvSource({ "42, 3000, 2000", "15, 5000, 1235", "20, 1000, 50" })
+    @CsvSource({"42, 3000, 2000", "15, 5000, 1235", "20, 1000, 50"})
     public void stressTest(int seed, int size, int k) {
-        Comparator<IPriorityQueue.PQElement<Integer>> c = (x, y) -> Double.compare(x.priority, y.priority);
+        Comparator<IPriorityQueue.PQElement<Integer>> c = Comparator.comparingDouble(x -> x.priority);
         Random r = new Random(seed);
         Integer[] intarray = r.ints(size).boxed().toArray(Integer[]::new);
         Double[] doublearray = Arrays.stream(intarray).map(Double::valueOf).toArray(Double[]::new);
-        IPriorityQueue.PQElement[] array = new IPriorityQueue.PQElement[intarray.length];
+        IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[intarray.length];
         for (int i = 0; i < intarray.length; i++) {
-            array[i] = new IPriorityQueue.PQElement(intarray[i], doublearray[i]);
+            array[i] = new IPriorityQueue.PQElement<>(intarray[i], doublearray[i]);
         }
         IPriorityQueue.PQElement<Integer>[] sortedArray = array.clone();
         Arrays.sort(sortedArray, c);
-        IPriorityQueue.PQElement[] correct = new IPriorityQueue.PQElement[size];
+        IPriorityQueue.PQElement<Integer>[] correct = new IPriorityQueue.PQElement[size];
         for (int i = 0; i < correct.length; i++) {
             if (i < k) {
                 correct[i] = sortedArray[sortedArray.length - i - 1];
-- 
GitLab


From 7afb76452e7a0d92fa3be22f434fb41ce89c5826 Mon Sep 17 00:00:00 2001
From: Ethan Ordentlich <eordentl@Caltech.edu>
Date: Fri, 12 Feb 2021 23:32:41 -0800
Subject: [PATCH 3/6] Miscellaneous cleanup changes

---
 src/wordsuggestor/ParseFBMessages.java                     | 1 +
 tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/wordsuggestor/ParseFBMessages.java b/src/wordsuggestor/ParseFBMessages.java
index 5499d9d..889d91a 100644
--- a/src/wordsuggestor/ParseFBMessages.java
+++ b/src/wordsuggestor/ParseFBMessages.java
@@ -5,6 +5,7 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Iterator;
 
+import edu.caltech.cs2.datastructures.ArrayDeque;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
diff --git a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
index 71bb6ee..2420f7e 100644
--- a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
+++ b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
@@ -130,7 +130,7 @@ public class MinFourHeapTests {
 
     @Tag("C")
     @ParameterizedTest(name = "Stress test enqueue and dequeue.")
-    @CsvSource({"100, 30000", "42, 10000"})
+    @CsvSource({"100, 10000", "42, 10000"})
     public void stressTestAddRemove(int seed, int size) {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         Comparator<Integer> c = new IntegerComparator();
-- 
GitLab


From 2ef85bc331fccf99b0899d31624270c1551c17b4 Mon Sep 17 00:00:00 2001
From: Ethan Ordentlich <eordentl@Caltech.edu>
Date: Sun, 14 Feb 2021 13:47:15 -0800
Subject: [PATCH 4/6] Another set of changes!

---
 .../org_hamcrest_hamcrest_all_1_3.xml         |  10 -
 .idea/libraries/org_jsoup_jsoup_1_11_31.xml   |  10 -
 ...jupiter_junit_jupiter_params_5_4_0_RC2.xml |  14 -
 .idea/workspace.xml                           | 173 +++++++++---
 project06-beaverchat.iml                      |   6 +-
 .../cs2/datastructures/MinFourHeap.java       |   2 +-
 .../cs2/interfaces/IPriorityQueue.java        |  12 +-
 .../cs2/datastructures/MinFourHeapTests.java  | 260 +++++++++++-------
 tests/edu/caltech/cs2/helpers/Inspection.java |  33 ++-
 9 files changed, 332 insertions(+), 188 deletions(-)
 delete mode 100644 .idea/libraries/org_hamcrest_hamcrest_all_1_3.xml
 delete mode 100644 .idea/libraries/org_jsoup_jsoup_1_11_31.xml
 delete mode 100644 .idea/libraries/org_junit_jupiter_junit_jupiter_params_5_4_0_RC2.xml

diff --git a/.idea/libraries/org_hamcrest_hamcrest_all_1_3.xml b/.idea/libraries/org_hamcrest_hamcrest_all_1_3.xml
deleted file mode 100644
index 527714b..0000000
--- a/.idea/libraries/org_hamcrest_hamcrest_all_1_3.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<component name="libraryTable">
-  <library name="org.hamcrest:hamcrest-all:1.3" type="repository">
-    <properties maven-id="org.hamcrest:hamcrest-all:1.3" />
-    <CLASSES>
-      <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar!/" />
-    </CLASSES>
-    <JAVADOC />
-    <SOURCES />
-  </library>
-</component>
\ No newline at end of file
diff --git a/.idea/libraries/org_jsoup_jsoup_1_11_31.xml b/.idea/libraries/org_jsoup_jsoup_1_11_31.xml
deleted file mode 100644
index 4de9727..0000000
--- a/.idea/libraries/org_jsoup_jsoup_1_11_31.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<component name="libraryTable">
-  <library name="org.jsoup:jsoup:1.11.31" type="repository">
-    <properties maven-id="org.jsoup:jsoup:1.11.3" />
-    <CLASSES>
-      <root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.11.3/jsoup-1.11.3.jar!/" />
-    </CLASSES>
-    <JAVADOC />
-    <SOURCES />
-  </library>
-</component>
\ No newline at end of file
diff --git a/.idea/libraries/org_junit_jupiter_junit_jupiter_params_5_4_0_RC2.xml b/.idea/libraries/org_junit_jupiter_junit_jupiter_params_5_4_0_RC2.xml
deleted file mode 100644
index 2d96221..0000000
--- a/.idea/libraries/org_junit_jupiter_junit_jupiter_params_5_4_0_RC2.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<component name="libraryTable">
-  <library name="org.junit.jupiter:junit-jupiter-params:5.4.0-RC2" type="repository">
-    <properties maven-id="org.junit.jupiter:junit-jupiter-params:5.4.0-M1" />
-    <CLASSES>
-      <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.4.0-M1/junit-jupiter-params-5.4.0-M1.jar!/" />
-      <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
-      <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.4.0-M1/junit-jupiter-api-5.4.0-M1.jar!/" />
-      <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
-      <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.4.0-M1/junit-platform-commons-1.4.0-M1.jar!/" />
-    </CLASSES>
-    <JAVADOC />
-    <SOURCES />
-  </library>
-</component>
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ac70327..ff5d7e3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,16 +2,17 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="85b5a371-aaad-42bc-ba46-b3dd6c4e178b" name="Default Changelist" comment="">
-      <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/libraries/org_hamcrest_hamcrest_all_1_3.xml" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/libraries/org_jsoup_jsoup_1_11_31.xml" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/libraries/org_junit_jupiter_junit_jupiter_params_5_4_0_RC2.xml" beforeDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDeque.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDeque.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDictionary.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IDictionary.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IList.java" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/project06-beaverchat.iml" beforeDir="false" afterPath="$PROJECT_DIR$/project06-beaverchat.iml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/datastructures/MinFourHeap.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/datastructures/MinFourHeap.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IPriorityQueue.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/interfaces/IPriorityQueue.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/sorts/TopKSort.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/sorts/TopKSort.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/edu/caltech/cs2/types/NGram.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/edu/caltech/cs2/types/NGram.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/HeapTester.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/NGramMapTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/NGramMapTests.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/sorts/SortTester.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/sorts/SortTester.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/tests/edu/caltech/cs2/helpers/Inspection.java" beforeDir="false" afterPath="$PROJECT_DIR$/tests/edu/caltech/cs2/helpers/Inspection.java" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -79,6 +80,14 @@
     </option>
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
   </component>
+  <component name="GitSEFilterConfiguration">
+    <file-type-list>
+      <filtered-out-file-type name="LOCAL_BRANCH" />
+      <filtered-out-file-type name="REMOTE_BRANCH" />
+      <filtered-out-file-type name="TAG" />
+      <filtered-out-file-type name="COMMIT_BY_MESSAGE" />
+    </file-type-list>
+  </component>
   <component name="IdeDocumentHistory">
     <option name="CHANGED_PATHS">
       <list>
@@ -301,7 +310,7 @@
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrary" value="Groovy JUnit" />
     <property name="com.intellij.testIntegration.createTest.CreateTestDialog.defaultLibrarySuperClass.Groovy JUnit" value="groovy.util.GroovyTestCase" />
     <property name="last_opened_file_path" value="$PROJECT_DIR$/src/edu/caltech/cs2/datastructures" />
-    <property name="project.structure.last.edited" value="Project" />
+    <property name="project.structure.last.edited" value="Libraries" />
     <property name="project.structure.proportion" value="0.15" />
     <property name="project.structure.side.proportion" value="0.39310345" />
     <property name="settings.editor.selected.configurable" value="project.propVCSSupport.Mappings" />
@@ -336,62 +345,117 @@
       <recent name="edu.caltech.cs2.types" />
     </key>
   </component>
-  <component name="RunManager" selected="JUnit.A Tests">
-    <configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="beaverchat.Main" />
+  <component name="RunManager" selected="JUnit.MinFourHeapTests.stressTestEnqueueDequeue">
+    <configuration name="A Tests" type="JUnit" factoryName="JUnit">
+      <module name="project06-beaverchat" />
+      <option name="MAIN_CLASS_NAME" value="" />
+      <option name="METHOD_NAME" value="" />
+      <option name="TEST_OBJECT" value="tags" />
+      <option name="PARAMETERS" value="" />
+      <tag value="A" />
+      <method v="2">
+        <option name="Make" enabled="true" />
+      </method>
+    </configuration>
+    <configuration name="B Tests" type="JUnit" factoryName="JUnit">
+      <module name="project06-beaverchat" />
+      <option name="MAIN_CLASS_NAME" value="" />
+      <option name="METHOD_NAME" value="" />
+      <option name="TEST_OBJECT" value="tags" />
+      <option name="PARAMETERS" value="" />
+      <tag value="B" />
+      <method v="2">
+        <option name="Make" enabled="true" />
+      </method>
+    </configuration>
+    <configuration name="C tests" type="JUnit" factoryName="JUnit">
+      <module name="project06-beaverchat" />
+      <option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
+      <option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.HeapTester" />
+      <option name="METHOD_NAME" value="" />
+      <option name="TEST_OBJECT" value="tags" />
+      <option name="PARAMETERS" value="" />
+      <tag value="C" />
+      <method v="2">
+        <option name="Make" enabled="true" />
+      </method>
+    </configuration>
+    <configuration name="MinFourHeapTests.blargh" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="project06-beaverchat" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="beaverchat.*" />
+          <option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
+      <option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
+      <option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.MinFourHeapTests" />
+      <option name="METHOD_NAME" value="blargh" />
+      <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="ParseFBMessages" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="wordsuggestor.ParseFBMessages" />
+    <configuration name="MinFourHeapTests.stressTestEnqueueDequeue" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="project06-beaverchat" />
-      <option name="PROGRAM_PARAMETERS" value="&quot;Anirudh Mathukumilli&quot; $PROJECT_DIR$/../Downloads/fbMessages" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="wordsuggestor.*" />
+          <option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
+      <option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
+      <option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.MinFourHeapTests" />
+      <option name="METHOD_NAME" value="stressTestEnqueueDequeue(int,int)" />
+      <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="A Tests" type="JUnit" factoryName="JUnit">
+    <configuration name="MinFourHeapTests.testDequeue" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="project06-beaverchat" />
-      <option name="MAIN_CLASS_NAME" value="" />
-      <option name="METHOD_NAME" value="" />
-      <option name="TEST_OBJECT" value="tags" />
-      <option name="PARAMETERS" value="" />
-      <tag value="A" />
+      <extension name="coverage">
+        <pattern>
+          <option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
+          <option name="ENABLED" value="true" />
+        </pattern>
+      </extension>
+      <option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
+      <option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.MinFourHeapTests" />
+      <option name="METHOD_NAME" value="testDequeue" />
+      <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="B Tests" type="JUnit" factoryName="JUnit">
+    <configuration name="MinFourHeapTests.testDequeueNoShift" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="project06-beaverchat" />
-      <option name="MAIN_CLASS_NAME" value="" />
-      <option name="METHOD_NAME" value="" />
-      <option name="TEST_OBJECT" value="tags" />
-      <option name="PARAMETERS" value="" />
-      <tag value="B" />
+      <extension name="coverage">
+        <pattern>
+          <option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
+          <option name="ENABLED" value="true" />
+        </pattern>
+      </extension>
+      <option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
+      <option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.MinFourHeapTests" />
+      <option name="METHOD_NAME" value="testDequeueNoShift" />
+      <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="C tests" type="JUnit" factoryName="JUnit">
+    <configuration name="MinFourHeapTests.testEnqueue" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="project06-beaverchat" />
+      <extension name="coverage">
+        <pattern>
+          <option name="PATTERN" value="edu.caltech.cs2.datastructures.*" />
+          <option name="ENABLED" value="true" />
+        </pattern>
+      </extension>
       <option name="PACKAGE_NAME" value="edu.caltech.cs2.datastructures" />
-      <option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.HeapTester" />
-      <option name="METHOD_NAME" value="" />
-      <option name="TEST_OBJECT" value="tags" />
+      <option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.datastructures.MinFourHeapTests" />
+      <option name="METHOD_NAME" value="testEnqueue" />
+      <option name="TEST_OBJECT" value="method" />
       <option name="PARAMETERS" value="" />
       <tag value="C" />
       <method v="2">
@@ -399,16 +463,22 @@
       </method>
     </configuration>
     <list>
-      <item itemvalue="Application.Main" />
-      <item itemvalue="Application.ParseFBMessages" />
       <item itemvalue="JUnit.C tests" />
       <item itemvalue="JUnit.B Tests" />
       <item itemvalue="JUnit.A Tests" />
+      <item itemvalue="JUnit.MinFourHeapTests.testDequeueNoShift" />
+      <item itemvalue="JUnit.MinFourHeapTests.testEnqueue" />
+      <item itemvalue="JUnit.MinFourHeapTests.blargh" />
+      <item itemvalue="JUnit.MinFourHeapTests.testDequeue" />
+      <item itemvalue="JUnit.MinFourHeapTests.stressTestEnqueueDequeue" />
     </list>
     <recent_temporary>
       <list>
-        <item itemvalue="Application.Main" />
-        <item itemvalue="Application.ParseFBMessages" />
+        <item itemvalue="JUnit.MinFourHeapTests.stressTestEnqueueDequeue" />
+        <item itemvalue="JUnit.MinFourHeapTests.testDequeue" />
+        <item itemvalue="JUnit.MinFourHeapTests.blargh" />
+        <item itemvalue="JUnit.MinFourHeapTests.testEnqueue" />
+        <item itemvalue="JUnit.MinFourHeapTests.testDequeueNoShift" />
       </list>
     </recent_temporary>
   </component>
@@ -669,7 +739,28 @@
       <option name="project" value="LOCAL" />
       <updated>1550070167911</updated>
     </task>
-    <option name="localTasksCounter" value="36" />
+    <task id="LOCAL-00036" summary="Miscellaneous cleanup changes">
+      <created>1613195494985</created>
+      <option name="number" value="00036" />
+      <option name="presentableId" value="LOCAL-00036" />
+      <option name="project" value="LOCAL" />
+      <updated>1613195494985</updated>
+    </task>
+    <task id="LOCAL-00037" summary="Miscellaneous cleanup changes">
+      <created>1613195601307</created>
+      <option name="number" value="00037" />
+      <option name="presentableId" value="LOCAL-00037" />
+      <option name="project" value="LOCAL" />
+      <updated>1613195601307</updated>
+    </task>
+    <task id="LOCAL-00038" summary="Miscellaneous cleanup changes">
+      <created>1613201561134</created>
+      <option name="number" value="00038" />
+      <option name="presentableId" value="LOCAL-00038" />
+      <option name="project" value="LOCAL" />
+      <updated>1613201561134</updated>
+    </task>
+    <option name="localTasksCounter" value="39" />
     <servers />
   </component>
   <component name="TestHistory">
@@ -784,7 +875,6 @@
       <path value="$USER_HOME$" />
       <path value="$PROJECT_DIR$/../.." />
     </ignored-roots>
-    <MESSAGE value="Work on spelling correction&#10;&#10;The spell check now computes all possible words of edit distance&#10;two. All that remains is choosing the most likely one." />
     <MESSAGE value="Finish implementing spelling correction.&#10;&#10;Now I just have to write a bunch of tests. I did finish the &#10;NGramMap tests." />
     <MESSAGE value="Implement getBestSuggestion &#10;&#10;I now have a function that will return the top suggestion in&#10;the ngrams map." />
     <MESSAGE value="Finish getPossibleCorrectionsTest&#10;&#10;I now have a test that checks whether or not students are &#10;correctly retrieving all possible corrections." />
@@ -809,14 +899,15 @@
     <MESSAGE value="Flesh out spec&#10;&#10;The spec now fully fleshes out all of the students' tasks&#10;Edit distance is still horribly explained, but I cannot &#10;seem to make it better&#10;Spec is ugly; needs some serious formatting love" />
     <MESSAGE value="Move chat files around&#10;&#10;Chat web client files were thrown around everywhere, so I &#10;consolidated them" />
     <MESSAGE value="Clean up js&#10;&#10;Mostly just commented and moved around js so it wasn't so &#10;messy. Could definitely be improved, but js is not my forte" />
-    <option name="LAST_COMMIT_MESSAGE" value="Clean up js&#10;&#10;Mostly just commented and moved around js so it wasn't so &#10;messy. Could definitely be improved, but js is not my forte" />
+    <MESSAGE value="Miscellaneous cleanup changes" />
+    <option name="LAST_COMMIT_MESSAGE" value="Miscellaneous cleanup changes" />
   </component>
   <component name="XDebuggerManager">
     <breakpoint-manager>
       <breakpoints>
         <line-breakpoint type="java-line">
           <url>file://$PROJECT_DIR$/src/wordsuggestor/ParseFBMessages.java</url>
-          <line>42</line>
+          <line>43</line>
           <option name="timeStamp" value="67" />
         </line-breakpoint>
         <line-breakpoint type="java-line">
diff --git a/project06-beaverchat.iml b/project06-beaverchat.iml
index e238e70..bbfc577 100644
--- a/project06-beaverchat.iml
+++ b/project06-beaverchat.iml
@@ -8,9 +8,9 @@
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" scope="TEST" name="org.hamcrest:hamcrest-all:1.3" level="project" />
-    <orderEntry type="library" name="org.junit.jupiter:junit-jupiter-params:5.4.0-RC2" level="project" />
     <orderEntry type="library" name="com.github.javaparser:javaparser-core:3.5.121" level="project" />
-    <orderEntry type="library" name="org.jsoup:jsoup:1.11.31" level="project" />
+    <orderEntry type="library" name="org.hamcrest:hamcrest-core:2.2" level="project" />
+    <orderEntry type="library" name="org.jsoup:jsoup:1.13.1" level="project" />
+    <orderEntry type="library" name="org.junit.jupiter:junit-jupiter:5.6.0-M1" level="project" />
   </component>
 </module>
\ No newline at end of file
diff --git a/src/edu/caltech/cs2/datastructures/MinFourHeap.java b/src/edu/caltech/cs2/datastructures/MinFourHeap.java
index 7c39885..7e91ff5 100644
--- a/src/edu/caltech/cs2/datastructures/MinFourHeap.java
+++ b/src/edu/caltech/cs2/datastructures/MinFourHeap.java
@@ -7,7 +7,7 @@ import java.util.Iterator;
 
 public class MinFourHeap<E> implements IPriorityQueue<E> {
 
-    private static final int DEFAULT_CAPACITY = 5;
+    private static final int DEFAULT_CAPACITY = 10;
 
     private int size;
     private PQElement<E>[] data;
diff --git a/src/edu/caltech/cs2/interfaces/IPriorityQueue.java b/src/edu/caltech/cs2/interfaces/IPriorityQueue.java
index 46f8738..721b3ad 100644
--- a/src/edu/caltech/cs2/interfaces/IPriorityQueue.java
+++ b/src/edu/caltech/cs2/interfaces/IPriorityQueue.java
@@ -2,7 +2,7 @@ package edu.caltech.cs2.interfaces;
 
 /**
  * This interface represents a Priority Queue - a data structure that is very similar to a queue but
- * stores values in ascending order.
+ * stores values in ascending order based on their priority.
  * @param <E> Element type
  */
 public interface IPriorityQueue<E> extends IQueue<IPriorityQueue.PQElement<E>> {
@@ -36,14 +36,16 @@ public interface IPriorityQueue<E> extends IQueue<IPriorityQueue.PQElement<E>> {
 
 
     /**
-     * Increase the priority of the key at idx
-     * @param key - the new key with the new priority
+     * Increase the priority of the element in the queue with data equal to key.data
+     * @param key - the PQElement with data, and new priority for that data
+     * @throws IllegalArgumentException if key.data is not an element in the queue
      */
     public void increaseKey(PQElement<E> key);
 
     /**
-     * Decrease the priority of the key at idx
-     * @param key - the new key with the new priority
+     * Decrease the priority of the element in the queue with data equal to key.data
+     * @param key - the PQElement with data, and new priority for that data
+     * @throws IllegalArgumentException if key.data is not an element in the queue
      */
     public void decreaseKey(PQElement<E> key);
 
diff --git a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
index 2420f7e..58eadfd 100644
--- a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
+++ b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
@@ -5,9 +5,7 @@ import edu.caltech.cs2.helpers.Reflection;
 
 import java.util.*;
 import java.util.ArrayList;
-import java.util.stream.Collectors;
 
-import edu.caltech.cs2.interfaces.ICollection;
 import edu.caltech.cs2.interfaces.IDictionary;
 import edu.caltech.cs2.interfaces.IPriorityQueue;
 import edu.caltech.cs2.misc.IntegerComparator;
@@ -17,21 +15,58 @@ import org.junit.jupiter.params.provider.CsvSource;
 
 import static org.junit.jupiter.api.Assertions.*;
 
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
 public class MinFourHeapTests {
     private static String STRING_SOURCE = "src/edu/caltech/cs2/datastructures/MinFourHeap.java";
 
+    public void checkKeyToIndexMap(MinFourHeap<Integer> heap) {
+        // Check keyToIndexMap
+        IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        IDictionary<Integer, Integer> indexMap = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
+                heap);
+        assertEquals(heap.size(), indexMap.size(), "Heap size and keyToIndexMap sizes are different");
+
+        // Reconstruct data from map
+        Integer[] dataFromMap = new Integer[heap.size()];
+        for (IDictionary.Entry<Integer, Integer> entry : indexMap.entrySet()) {
+            assertTrue(entry.value < heap.size(), "Index in keyToIndexMap is larger than heap size");
+            // If not null, then was set prior
+            assertNull(dataFromMap[entry.value], "Index appears multiple times in keyToIndexMap");
+            dataFromMap[entry.value] = entry.key;
+        }
+
+        // Only check data that's actually in the heap
+        for (int i = 0; i < heap.size(); i++) {
+            assertEquals(heapData[i].data, dataFromMap[i], "keyToIndexMap does not match heap data at index " + i);
+        }
+    }
+
     @Order(0)
     @DisplayName("Does not use or import disallowed classes")
     @Test
     @Tag("C")
     public void testForInvalidClasses() {
-        List<String> regexps = List.of("java.util.(?!Iterator|function.Function)", "java.lang.reflect", "java.io");
+        List<String> regexps = List.of("java.lang.reflect", "java.io");
         Inspection.assertNoImportsOf(STRING_SOURCE, regexps);
         Inspection.assertNoUsageOf(STRING_SOURCE, regexps);
     }
 
+    @Order(1)
+    @DisplayName("Does not use or import disallowed classes from java.util")
+    @Test
+    @Tag("C")
+    public void testForInvalidImportsJavaUtil() {
+        List<String> allowed = List.of("Iterator");
+        Inspection.assertNoImportsOfExcept(STRING_SOURCE, "java\\.util", allowed);
+
+        List<String> bannedUsages = List.of("java\\.util\\.(?!" + String.join("|", allowed) + ")");
+        Inspection.assertNoUsageOf(STRING_SOURCE, bannedUsages);
+    }
+
     @Test
     @Tag("C")
+    @Order(2)
+    @DisplayName("The public interface is correct")
     public void testPublicInterface() {
         Reflection.assertPublicInterface(MinFourHeap.class,
                 List.of("enqueue", "dequeue", "iterator", "decreaseKey", "increaseKey", "peek", "size"));
@@ -39,6 +74,8 @@ public class MinFourHeapTests {
 
     @Test
     @Tag("C")
+    @Order(3)
+    @DisplayName("Attempting to enqueue duplicate elements throws an exception")
     public void testDuplicateThrows() {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         heap.enqueue(new IPriorityQueue.PQElement<>(10, 10));
@@ -49,8 +86,9 @@ public class MinFourHeapTests {
 
     @Test
     @Tag("C")
-    public void testIdxTooLargeThrows() {
-        Comparator<Integer> c = new IntegerComparator();
+    @Order(3)
+    @DisplayName("Attempting to modify the priority of a nonexistent element throws an exception")
+    public void testChangeKeyNonexistentElem() {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         heap.enqueue(new IPriorityQueue.PQElement<>(10, 10));
         assertThrows(IllegalArgumentException.class, () -> {
@@ -63,6 +101,23 @@ public class MinFourHeapTests {
 
     @Test
     @Tag("C")
+    @Order(4)
+    public void testDequeueWithNoPercolation() {
+        MinFourHeap<Integer> heap = new MinFourHeap<>();
+        List<Integer> values = new ArrayList<>(Arrays.asList(1, 6, 7, 8, 2));
+        for (int value : values) {
+            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
+        }
+        // Dequeueing 1 won't cause any further percolations, since 2 is in the right place.
+        // There's some edge cases around this for some reason, which is why the test is here...
+        assertEquals(1, heap.dequeue().data);
+        checkKeyToIndexMap(heap);
+    }
+
+    @Test
+    @Tag("C")
+    @Order(5)
+    @DisplayName("Smoke test enqueue while checking internal state of heap")
     public void testEnqueue() {
         // create heap
         MinFourHeap<Integer> heap = new MinFourHeap<>();
@@ -87,139 +142,122 @@ public class MinFourHeapTests {
             assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))));
             assertEquals(i + 1, heap.size());
 
-            IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+            IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
             for (int j = 0; j < heap.size(); j++) {
-                assertEquals(step_by_step.get(i).toArray()[j], heap_data[j].data);
+                assertEquals(step_by_step.get(i).toArray()[j], heapData[j].data);
             }
 
-            // Make sure keyToIndexMap is updated correctly
-            IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
-                    heap);
-            for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
-                assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
-            }
+            checkKeyToIndexMap(heap);
         }
     }
 
     @Test
     @Tag("C")
+    @Order(5)
+    @DisplayName("Smoke test dequeue while checking internal state of heap")
     public void testDequeue() {
         Comparator<Integer> c = new IntegerComparator();
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         PriorityQueue<Integer> reference = new PriorityQueue<>(c);
         List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
-        for (int i = 0; i < values.size(); i++) {
-            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i))));
-            reference.add(values.get(i));
+        for (int value : values) {
+            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
+            reference.add(value);
         }
         for (int i = 0; i < reference.size(); i++) {
             assertEquals(reference.remove(), heap.dequeue().data);
-
-            // Check keyToIndexMap
-            IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
-            IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
-                    heap);
-            for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
-                assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
-            }
-
-            assertEquals(reference.size(), heap.size());
-        }
-
-    }
-
-    @Tag("C")
-    @ParameterizedTest(name = "Stress test enqueue and dequeue.")
-    @CsvSource({"100, 10000", "42, 10000"})
-    public void stressTestAddRemove(int seed, int size) {
-        MinFourHeap<Integer> heap = new MinFourHeap<>();
-        Comparator<Integer> c = new IntegerComparator();
-        PriorityQueue<Integer> reference = new PriorityQueue<>(c);
-        Random r = new Random(seed);
-        for (int i = 0; i < size; i++) {
-            int num = r.nextInt();
-            while (reference.contains(num)) {
-                num = r.nextInt();
-            }
-            reference.add(num);
-            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(num, num)));
-
-            // Check at intervals to save computation
-            if (i % 499 == 0) {
-                IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
-                IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
-                        heap);
-                for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
-                    assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
-                }
-            }
-
+            checkKeyToIndexMap(heap);
             assertEquals(reference.size(), heap.size());
         }
-        while (heap.size() != 0) {
-            assertEquals(reference.remove(), heap.dequeue().data);
-
-            if (heap.size() % 499 == 0) {
-                IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
-                IDictionary<Integer, Integer> index_map = Reflection.getFieldValue(MinFourHeap.class, "keyToIndexMap",
-                        heap);
-                for (IDictionary.Entry<Integer, Integer> entry : index_map.entrySet()) {
-                    if (heap_data[entry.value] == null) {
-                        // End of dequeue process
-                        assertTrue(heap.size() <= 2, "Heap contains null value");
-                        continue;
-                    }
-                    assertEquals(heap_data[entry.value].data, entry.key, "keyToIndexMap does not match heap data");
-                }
-            }
-        }
     }
 
     @Test
     @Tag("C")
+    @Order(6)
+    @DisplayName("Smoke test increaseKey while checking internal state of heap")
     public void testIncreaseKey() {
-        Comparator<Integer> c = new IntegerComparator();
+        // Build heap
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
         for (Integer value : values) {
             assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
         }
+        // Assert constructed heap is correct
         Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
-        IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int j = 0; j < heap.size(); j++) {
-            assertEquals(correctHeapData[j], heap_data[j].data);
+            assertEquals(correctHeapData[j], heapData[j].data);
         }
+        // Increase the root's priority
         heap.increaseKey(new IPriorityQueue.PQElement<>(-100, 100));
+
+        // Verify the heap after moving is correct
         double[] correctHeapPrioritiesAfterIncrease = {-84, -4, 2, 3, -2, 9, 7, 1, 100, 19, 70};
-        heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        checkKeyToIndexMap(heap);
         for (int i = 0; i < heap.size(); i++) {
-            assertEquals(correctHeapPrioritiesAfterIncrease[i], (double) heap_data[i].priority);
+            assertEquals(correctHeapPrioritiesAfterIncrease[i], heapData[i].priority);
         }
     }
 
     @Test
     @Tag("C")
+    @Order(6)
+    @DisplayName("Smoke test decreaseKey while checking internal state of heap")
     public void testDecreaseKey() {
+        // Build heap
         MinFourHeap<Integer> heap = new MinFourHeap<>();
         List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70));
         for (Integer value : values) {
             assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
         }
+
+        // Assert constructed heap is correct
         Integer[] correctHeapData = {-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70};
-        IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
         for (int j = 0; j < heap.size(); j++) {
-            assertEquals(correctHeapData[j], heap_data[j].data);
+            assertEquals(correctHeapData[j], heapData[j].data);
         }
+        // Decrease some node's priority
         heap.decreaseKey(new IPriorityQueue.PQElement<>(7, -105));
+
+        // Verify the heap after moving is correct
         double[] correctHeapPrioritiesAfterDecrease = {-105, -100, 2, 3, -2, 9, -84, 1, -4, 19, 70};
-        heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        checkKeyToIndexMap(heap);
         for (int i = 0; i < heap.size(); i++) {
-            assertEquals(correctHeapPrioritiesAfterDecrease[i], heap_data[i].priority);
+            assertEquals(correctHeapPrioritiesAfterDecrease[i], heapData[i].priority);
         }
     }
 
     @Tag("C")
-    @ParameterizedTest(name = "Stress test increase/decrease key")
+    @Order(6)
+    @Test
+    @DisplayName("Check that increaseKey that percolates near end of array does not throw")
+    public void testDecreaseKeyBeyondArrayBounds() {
+        MinFourHeap<Integer> heap = new MinFourHeap<>();
+        // Heap:
+        // 0 => [2 => [5, 6, 7, 8], 1 => [9], 3 => [], 4 => []]
+        List<Integer> values = new ArrayList<>(Arrays.asList(0, 2, 1, 3, 4, 5, 6, 7, 8, 9));
+        for (int value : values) {
+            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
+        }
+        IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+        // Make sure our heap data is still "good" for the test
+        assertEquals(10, heapData.length, "Heap data array is not a default size of 10 or was resized prematurely");
+
+        // Increase the node at the root. The node gets swapped with 1, then compared against children.
+        // But, 9 is at the last index in the heap array and not the last child.
+        heap.increaseKey(new IPriorityQueue.PQElement<>(0, 100));
+        // Correctness is checked elsewhere, so don't do anything here. Only thing that matters is that this
+        // executes successfully.
+        // 1 => [2 => [5, 6, 7, 8], 9 => [0 (100)], 3 => [], 4 => []]
+    }
+
+    @Tag("C")
+    @Order(7)
+    @ParameterizedTest(name = "Stress test increaseKey and decreaseKey with {1} random elements and seed = {0}")
+    @DisplayName("Stress test increaseKey, decreaseKey")
     @CsvSource({"100, 30000, 15000", "42, 10000, 5000"})
     public void stressTestIncreaseDecrease(int seed, int size, int numToReplace) {
         MinFourHeap<Integer> heap = new MinFourHeap<>();
@@ -238,26 +276,24 @@ public class MinFourHeapTests {
         }
 
         for (int j = 0; j < numToReplace; j++) {
-            int newKey = r.nextInt();
-            while (reference.contains(newKey) || removed.contains(newKey)) {
-                newKey = r.nextInt();
+            int newPriority = r.nextInt();
+            while (reference.contains(newPriority) || removed.contains(newPriority)) {
+                newPriority = r.nextInt();
             }
-            IPriorityQueue.PQElement<Integer>[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
-            int idx = r.nextInt(heap.size());
-            Integer origKey = heap_data[idx].data;
+            IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap);
+            Integer origKey = heapData[r.nextInt(heap.size())].data;
             while (removed.contains(origKey)) {
-                idx = r.nextInt(heap.size());
-                origKey = heap_data[idx].data;
+                origKey = heapData[r.nextInt(heap.size())].data;
             }
-            if (newKey < origKey) {
-                heap.decreaseKey(new IPriorityQueue.PQElement<>(origKey, newKey));
+            if (newPriority < origKey) {
+                heap.decreaseKey(new IPriorityQueue.PQElement<>(origKey, newPriority));
             } else {
-                heap.increaseKey(new IPriorityQueue.PQElement<>(origKey, newKey));
+                heap.increaseKey(new IPriorityQueue.PQElement<>(origKey, newPriority));
             }
             assertEquals(reference.size(), heap.size());
             removed.add(origKey);
             reference.remove(origKey);
-            reference.add(newKey);
+            reference.add(newPriority);
             assertEquals(reference.size(), heap.size());
         }
         int i = 0;
@@ -272,6 +308,40 @@ public class MinFourHeapTests {
             assertEquals((double) er, mr.priority);
             i++;
         }
+    }
+
+    @Tag("C")
+    @Order(7)
+    @ParameterizedTest(name = "Stress test enqueue and dequeue with {1} random elements and seed = {0}")
+    @CsvSource({"100, 10000", "42, 10000"})
+    @DisplayName("Stress test enqueue, dequeue")
+    public void stressTestEnqueueDequeue(int seed, int size) {
+        MinFourHeap<Integer> heap = new MinFourHeap<>();
+        Comparator<Integer> c = new IntegerComparator();
+        PriorityQueue<Integer> reference = new PriorityQueue<>(c);
+        Random r = new Random(seed);
+        for (int i = 0; i < size; i++) {
+            int num = r.nextInt();
+            while (reference.contains(num)) {
+                num = r.nextInt();
+            }
+            reference.add(num);
+            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(num, num)));
+
+            // Check at intervals to save computation
+            if (i % 499 == 0) {
+                checkKeyToIndexMap(heap);
+            }
+
+            assertEquals(reference.size(), heap.size());
+        }
+        while (heap.size() != 0) {
+            assertEquals(reference.remove(), heap.dequeue().data);
 
+            if (heap.size() % 499 == 0) {
+                checkKeyToIndexMap(heap);
+            }
+        }
     }
+
 }
\ No newline at end of file
diff --git a/tests/edu/caltech/cs2/helpers/Inspection.java b/tests/edu/caltech/cs2/helpers/Inspection.java
index cdf089e..c3f1fca 100644
--- a/tests/edu/caltech/cs2/helpers/Inspection.java
+++ b/tests/edu/caltech/cs2/helpers/Inspection.java
@@ -18,11 +18,11 @@ import java.util.List;
 import static org.junit.jupiter.api.Assertions.fail;
 
 public class Inspection {
-  private static String getUsageOf(List<String> regexps, List<? extends Node> codeObjects) {
+  private static String[] getUsageOf(List<String> regexps, List<? extends Node> codeObjects) {
     for (Node d : codeObjects) {
       for (String regex : regexps) {
         if (d.toString().replaceAll("\\R", "").matches(".*" + regex + ".*")) {
-          return regex;
+          return new String[]{d.toString().replaceAll("\\R", ""), regex};
         }
       }
     }
@@ -32,9 +32,25 @@ public class Inspection {
   public static void assertNoImportsOf(String filePath, List<String> regexps) {
     try {
       CompilationUnit cu = JavaParser.parse(new File(filePath));
-      String usage = getUsageOf(regexps, cu.getImports());
+      String[] usage = getUsageOf(regexps, cu.getImports());
       if (usage != null) {
-        fail("You may not import " + usage + " in " + Paths.get(filePath).getFileName() + ".");
+        fail(usage[0] + " is a banned import under " + usage[1] + " in " + Paths.get(filePath).getFileName()
+                + ".");
+      }
+    } catch (FileNotFoundException e) {
+      fail("Missing Java file: " + Paths.get(filePath).getFileName());
+    }
+  }
+
+  public static void assertNoImportsOfExcept(String filePath, String bannedImport, List<String> allowedClasses) {
+    try {
+      CompilationUnit cu = JavaParser.parse(new File(filePath));
+      String bannedRegex = bannedImport + "\\.(?!" + String.join("|", allowedClasses) + ")";
+      String[] usage = getUsageOf(List.of(bannedRegex), cu.getImports());
+      if (usage != null) {
+        fail(usage[0] + " is a banned import under " + bannedImport +
+                " and is not an allowed import " +
+                allowedClasses + " in " + Paths.get(filePath).getFileName() + ".");
       }
     } catch (FileNotFoundException e) {
       fail("Missing Java file: " + Paths.get(filePath).getFileName());
@@ -66,16 +82,16 @@ public class Inspection {
 
       List<ConstructorDeclaration> constructors = new ArrayList<>();
       CONSTRUCTOR_COLLECTOR.visit(cu, constructors);
-      String usage = getUsageOf(regexps, constructors);
+      String[] usage = getUsageOf(regexps, constructors);
       if (usage != null) {
-        fail("You may not use " + usage + " in " + Paths.get(filePath).getFileName() + ".");
+        fail("You may not use " + usage[1] + " in " + Paths.get(filePath).getFileName() + ".");
       }
 
       List<MethodDeclaration> methods = new ArrayList<>();
       METHOD_COLLECTOR.visit(cu, methods);
       usage = getUsageOf(regexps, methods);
       if (usage != null) {
-        fail("You may not use " + usage + " in " + Paths.get(filePath).getFileName() + ".");
+        fail("You may not use " + usage[1] + " in " + Paths.get(filePath).getFileName() + ".");
       }
     } catch (FileNotFoundException e) {
       fail("Missing Java file: " + Paths.get(filePath).getFileName());
@@ -93,8 +109,7 @@ public class Inspection {
         List<Statement> statements = body.getStatements();
         if (statements.size() != 1) {
           nonThisConstructors++;
-        }
-        else if (!statements.get(0).toString().startsWith("this(")) {
+        } else if (!statements.get(0).toString().startsWith("this(")) {
           nonThisConstructors++;
         }
 
-- 
GitLab


From 6fceb9a8a4fd26f7c154b8395b450f6c6671d3aa Mon Sep 17 00:00:00 2001
From: Ethan Ordentlich <eordentl@Caltech.edu>
Date: Sun, 14 Feb 2021 14:15:45 -0800
Subject: [PATCH 5/6] tests go brrr

---
 .../cs2/datastructures/NGramMapTests.java     | 41 +++++++++++--------
 .../cs2/project06/SpellingCorrectorTests.java | 36 +++++++++-------
 .../{SortTester.java => TopKSortTests.java}   | 22 +++++++++-
 3 files changed, 65 insertions(+), 34 deletions(-)
 rename tests/edu/caltech/cs2/sorts/{SortTester.java => TopKSortTests.java} (80%)

diff --git a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
index 1b36aa2..0629923 100644
--- a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
+++ b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
@@ -5,10 +5,7 @@ import edu.caltech.cs2.interfaces.IDeque;
 import edu.caltech.cs2.interfaces.IDictionary;
 import edu.caltech.cs2.interfaces.IPriorityQueue;
 import edu.caltech.cs2.types.NGram;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.*;
 
 import java.util.List;
 import java.util.Scanner;
@@ -17,6 +14,7 @@ import java.util.function.Supplier;
 
 import static org.junit.jupiter.api.Assertions.*;
 
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
 public class NGramMapTests {
     private static String STRING_SOURCE = "src/edu/caltech/cs2/datastructures/NGramMap.java";
 
@@ -25,26 +23,25 @@ public class NGramMapTests {
     @Tag("B")
     @Test
     public void testForInvalidClasses() {
-        List<String> regexps = List.of("java.util.(?!Iterator|function.Function|function.Supplier|Random|Scanner)",
+        List<String> regexps = List.of(
                 "java.lang.reflect", "java.io");
         Inspection.assertNoImportsOf(STRING_SOURCE, regexps);
         Inspection.assertNoUsageOf(STRING_SOURCE, regexps);
     }
 
-    private static final String SRC_FILE_PATH = System.getProperty("user.dir") + "/data/test_ngrammap_src";
-    IDictionary<NGram, IDictionary<IterableString, Integer>> newOuter;
-    Supplier<IDictionary<IterableString, Integer>> newInner;
+    @Order(1)
+    @DisplayName("Does not use or import disallowed classes from java.util")
+    @Test
+    @Tag("B")
+    public void testForInvalidImportsJavaUtil() {
+        List<String> allowed = List.of("Iterator", "function.Supplier", "Random", "Scanner");
+        Inspection.assertNoImportsOfExcept(STRING_SOURCE, "java\\.util", allowed);
+
+        List<String> bannedUsages = List.of("java\\.util\\.(?!" + String.join("|", allowed) + ")");
+        Inspection.assertNoUsageOf(STRING_SOURCE, bannedUsages);
+    }
 
     private NGramMap initNGramMap(Scanner in, int N) {
-        Function<IDeque<String>, NGram> ngramCollector = NGram::new;
-        Function<IDeque<Character>, IterableString> stringCollector = (IDeque<Character> x) -> {
-            char[] chars = new char[x.size()];
-            for (int i = 0; i < chars.length; i++) {
-                chars[i] = x.peekFront();
-                x.addBack(x.removeFront());
-            }
-            return new IterableString(new String(chars));
-        };
         IDictionary<NGram, IDictionary<IterableString, Integer>> newOuter = new ChainingHashDictionary<>(
                 MoveToFrontDictionary::new);
         Supplier<IDictionary<IterableString, Integer>> newInner = () -> new ChainingHashDictionary<>(
@@ -54,6 +51,8 @@ public class NGramMapTests {
 
     @Test
     @Tag("B")
+    @Order(2)
+    @DisplayName("Test text containing a single NGram")
     public void testSingleNGram() {
         String text = "One two three";
         NGramMap map = initNGramMap(new Scanner(text), 2);
@@ -65,6 +64,8 @@ public class NGramMapTests {
 
     @Test
     @Tag("B")
+    @Order(3)
+    @DisplayName("Test text containing multiple NGrams")
     public void testMultipleNGram() {
         String text = "a a a a a a a a a a a a";
         NGramMap map = initNGramMap(new Scanner(text), 2);
@@ -76,6 +77,8 @@ public class NGramMapTests {
 
     @Test
     @Tag("B")
+    @Order(4)
+    @DisplayName("Test getCountsAfter on a nonexistent NGram")
     public void testNonexistentNGram() {
         NGramMap map = initNGramMap(new Scanner("blah blah"), 2);
         assertNull(map.getCountsAfter(new NGram("not in")));
@@ -83,6 +86,8 @@ public class NGramMapTests {
 
     @Test
     @Tag("B")
+    @Order(5)
+    @DisplayName("Test seenWordAfter")
     public void testSeenWordAfter() {
         String text = "The quick brown fox jumps over the lazy dog";
         NGramMap map = initNGramMap(new Scanner(text), 2);
@@ -107,6 +112,8 @@ public class NGramMapTests {
 
     @Test
     @Tag("B")
+    @Order(6)
+    @DisplayName("Test getWordsAfter")
     public void testGetWordsAfter() {
         String text = "The quick brown fox jumps over the lazy dog";
         NGramMap map = initNGramMap(new Scanner(text), 2);
diff --git a/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java b/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
index 20a6539..d616944 100644
--- a/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
+++ b/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
@@ -7,10 +7,7 @@ import edu.caltech.cs2.interfaces.IDeque;
 import edu.caltech.cs2.interfaces.IDictionary;
 import edu.caltech.cs2.misc.CorrectionChoice;
 import edu.caltech.cs2.types.NGram;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.*;
 import wordcorrector.SpellingCorrector;
 
 import java.io.File;
@@ -24,6 +21,7 @@ import java.util.function.Supplier;
 import static org.junit.jupiter.api.Assertions.*;
 
 
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
 public class SpellingCorrectorTests {
     private static final String DICT_FILENAME = "./data/dictionary.txt";
     private static final String EDIT_DIST_FILENAME = "./data/edit_distance_test";
@@ -39,21 +37,24 @@ public class SpellingCorrectorTests {
     @Test
     @Tag("A")
     public void testForInvalidClasses() {
-        List<String> regexps = List.of("java.util.(?!Iterator|function.Function)", "java.lang.reflect", "java.io");
+        List<String> regexps = List.of("java.lang.reflect", "java.io");
         Inspection.assertNoImportsOf(STRING_SOURCE, regexps);
         Inspection.assertNoUsageOf(STRING_SOURCE, regexps);
     }
 
+    @Order(0)
+    @DisplayName("Does not use or import disallowed classes from java.util")
+    @Test
+    @Tag("A")
+    public void testForInvalidClassesUtil() {
+        List<String> allowed = List.of("Iterator");
+        Inspection.assertNoImportsOfExcept(STRING_SOURCE, "java\\.util", allowed);
+
+        List<String> bannedUsages = List.of("java\\.util\\.(?!" + String.join("|", allowed) + ")");
+        Inspection.assertNoUsageOf(STRING_SOURCE, bannedUsages);
+    }
+
     private NGramMap initNGramMap(Scanner in, int N) {
-        Function<IDeque<String>, NGram> ngramCollector = NGram::new;
-        Function<IDeque<Character>, IterableString> stringCollector = (IDeque<Character> x) -> {
-            char[] chars = new char[x.size()];
-            for (int i = 0; i < chars.length; i++) {
-                chars[i] = x.peekFront();
-                x.addBack(x.removeFront());
-            }
-            return new IterableString(new String(chars));
-        };
         IDictionary<NGram, IDictionary<IterableString, Integer>> newOuter = new ChainingHashDictionary<>(MoveToFrontDictionary::new);
         Supplier<IDictionary<IterableString, Integer>> newInner = () -> new ChainingHashDictionary<>(MoveToFrontDictionary::new);
         return new NGramMap(in, N, newOuter, newInner);
@@ -61,6 +62,8 @@ public class SpellingCorrectorTests {
 
     @Test
     @Tag("A")
+    @Order(1)
+    @DisplayName("Test correctness and speed of editDistance")
     public void testEditDistance() {
         assertTimeout(Duration.ofMillis(EDIT_DIST_TIMEOUT), this::testEditDistanceHelper);
     }
@@ -81,6 +84,8 @@ public class SpellingCorrectorTests {
 
     @Test
     @Tag("A")
+    @Order(2)
+    @DisplayName("Test possibleCorrections")
     public void testPossibleCorrections() {
         File folder = new File(POSSIBLE_CORRECTIONS_DIRECTORY);
         File[] listOfFiles = folder.listFiles();
@@ -120,6 +125,8 @@ public class SpellingCorrectorTests {
 
     @Test
     @Tag("A")
+    @Order(3)
+    @DisplayName("Test bestCorrection")
     public void testBestCorrection () {
         // test best corrections
         SpellingCorrector corrector = new SpellingCorrector(DICT_FILENAME);
@@ -145,5 +152,4 @@ public class SpellingCorrectorTests {
                     elements[1], elements[2].strip(), 10));
         }
     }
-
 }
diff --git a/tests/edu/caltech/cs2/sorts/SortTester.java b/tests/edu/caltech/cs2/sorts/TopKSortTests.java
similarity index 80%
rename from tests/edu/caltech/cs2/sorts/SortTester.java
rename to tests/edu/caltech/cs2/sorts/TopKSortTests.java
index ad1f00e..a7c4272 100644
--- a/tests/edu/caltech/cs2/sorts/SortTester.java
+++ b/tests/edu/caltech/cs2/sorts/TopKSortTests.java
@@ -17,7 +17,7 @@ import java.util.Random;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-public class SortTester {
+public class TopKSortTests {
     private static String STRING_SOURCE = "src/edu/caltech/cs2/sorts/TopKSort.java";
 
     @Order(0)
@@ -25,13 +25,27 @@ public class SortTester {
     @Test
     @Tag("C")
     public void testForInvalidClasses() {
-        List<String> regexps = List.of("java.util.(?!Iterator|function.Function)", "java.lang.reflect", "java.io");
+        List<String> regexps = List.of("java.util", "java.lang.reflect", "java.io");
         Inspection.assertNoImportsOf(STRING_SOURCE, regexps);
         Inspection.assertNoUsageOf(STRING_SOURCE, regexps);
     }
 
+    @Order(0)
+    @DisplayName("Does not use or import disallowed classes from java.util")
+    @Test
+    @Tag("C")
+    public void testForInvalidClassesUtil() {
+        List<String> allowed = List.of("Iterator");
+        Inspection.assertNoImportsOfExcept(STRING_SOURCE, "java\\.util", allowed);
+
+        List<String> bannedUsages = List.of("java\\.util\\.(?!" + String.join("|", allowed) + ")");
+        Inspection.assertNoUsageOf(STRING_SOURCE, bannedUsages);
+    }
+
     @Test
     @Tag("C")
+    @Order(1)
+    @DisplayName("Sorting an empty array works as expected")
     public void testEmptyArray() {
         IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[0];
         TopKSort.sort(array, 1);
@@ -40,6 +54,8 @@ public class SortTester {
 
     @Test
     @Tag("C")
+    @Order(2)
+    @DisplayName("K < 0 throws an exception")
     public void testNegativeK() {
         IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[0];
         assertThrows(IllegalArgumentException.class, () -> {
@@ -49,6 +65,7 @@ public class SortTester {
 
     @Test
     @Tag("C")
+    @DisplayName("K = 0 does not change the array")
     public void testZeroK() {
         IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[]{
                 new IPriorityQueue.PQElement<>(1, 1), new IPriorityQueue.PQElement<>(2, 2),
@@ -63,6 +80,7 @@ public class SortTester {
     @Tag("C")
     @ParameterizedTest(name = "Stress test TopKSort: size: {1}, k: {2}")
     @CsvSource({"42, 3000, 2000", "15, 5000, 1235", "20, 1000, 50"})
+    @DisplayName("Stress test TopKSort")
     public void stressTest(int seed, int size, int k) {
         Comparator<IPriorityQueue.PQElement<Integer>> c = Comparator.comparingDouble(x -> x.priority);
         Random r = new Random(seed);
-- 
GitLab


From eebef5096179700c09f5e7980763ac5b37da83b8 Mon Sep 17 00:00:00 2001
From: Ethan Ordentlich <eordentl@Caltech.edu>
Date: Sun, 14 Feb 2021 14:40:02 -0800
Subject: [PATCH 6/6] more brrr

---
 .../cs2/datastructures/MinFourHeapTests.java  | 38 ++++++++++---------
 .../cs2/datastructures/NGramMapTests.java     |  2 -
 .../cs2/project06/SpellingCorrectorTests.java |  1 -
 .../edu/caltech/cs2/sorts/TopKSortTests.java  | 10 ++---
 4 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
index 58eadfd..2ccb962 100644
--- a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
+++ b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java
@@ -102,21 +102,6 @@ public class MinFourHeapTests {
     @Test
     @Tag("C")
     @Order(4)
-    public void testDequeueWithNoPercolation() {
-        MinFourHeap<Integer> heap = new MinFourHeap<>();
-        List<Integer> values = new ArrayList<>(Arrays.asList(1, 6, 7, 8, 2));
-        for (int value : values) {
-            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
-        }
-        // Dequeueing 1 won't cause any further percolations, since 2 is in the right place.
-        // There's some edge cases around this for some reason, which is why the test is here...
-        assertEquals(1, heap.dequeue().data);
-        checkKeyToIndexMap(heap);
-    }
-
-    @Test
-    @Tag("C")
-    @Order(5)
     @DisplayName("Smoke test enqueue while checking internal state of heap")
     public void testEnqueue() {
         // create heap
@@ -153,7 +138,7 @@ public class MinFourHeapTests {
 
     @Test
     @Tag("C")
-    @Order(5)
+    @Order(4)
     @DisplayName("Smoke test dequeue while checking internal state of heap")
     public void testDequeue() {
         Comparator<Integer> c = new IntegerComparator();
@@ -173,7 +158,7 @@ public class MinFourHeapTests {
 
     @Test
     @Tag("C")
-    @Order(6)
+    @Order(5)
     @DisplayName("Smoke test increaseKey while checking internal state of heap")
     public void testIncreaseKey() {
         // Build heap
@@ -202,7 +187,7 @@ public class MinFourHeapTests {
 
     @Test
     @Tag("C")
-    @Order(6)
+    @Order(5)
     @DisplayName("Smoke test decreaseKey while checking internal state of heap")
     public void testDecreaseKey() {
         // Build heap
@@ -230,6 +215,23 @@ public class MinFourHeapTests {
         }
     }
 
+    @Test
+    @Tag("C")
+    @Order(6)
+    @DisplayName("Dequeueing with no further percolation leaves the heap in a consistent state")
+    public void testDequeueWithNoPercolation() {
+        MinFourHeap<Integer> heap = new MinFourHeap<>();
+        List<Integer> values = new ArrayList<>(Arrays.asList(1, 6, 7, 8, 2));
+        for (int value : values) {
+            assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(value, value)));
+        }
+        // Dequeueing 1 won't cause any further percolations, since 2 is in the right place.
+        // There's some edge cases around this for some reason, which is why the test is here...
+        assertEquals(1, heap.dequeue().data);
+        checkKeyToIndexMap(heap);
+    }
+
+
     @Tag("C")
     @Order(6)
     @Test
diff --git a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
index 0629923..616ca84 100644
--- a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
+++ b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java
@@ -1,7 +1,6 @@
 package edu.caltech.cs2.datastructures;
 
 import edu.caltech.cs2.helpers.Inspection;
-import edu.caltech.cs2.interfaces.IDeque;
 import edu.caltech.cs2.interfaces.IDictionary;
 import edu.caltech.cs2.interfaces.IPriorityQueue;
 import edu.caltech.cs2.types.NGram;
@@ -9,7 +8,6 @@ import org.junit.jupiter.api.*;
 
 import java.util.List;
 import java.util.Scanner;
-import java.util.function.Function;
 import java.util.function.Supplier;
 
 import static org.junit.jupiter.api.Assertions.*;
diff --git a/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java b/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
index d616944..a650013 100644
--- a/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
+++ b/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java
@@ -15,7 +15,6 @@ import java.io.FileNotFoundException;
 import java.time.Duration;
 import java.util.List;
 import java.util.Scanner;
-import java.util.function.Function;
 import java.util.function.Supplier;
 
 import static org.junit.jupiter.api.Assertions.*;
diff --git a/tests/edu/caltech/cs2/sorts/TopKSortTests.java b/tests/edu/caltech/cs2/sorts/TopKSortTests.java
index a7c4272..765574d 100644
--- a/tests/edu/caltech/cs2/sorts/TopKSortTests.java
+++ b/tests/edu/caltech/cs2/sorts/TopKSortTests.java
@@ -2,10 +2,7 @@ package edu.caltech.cs2.sorts;
 
 import edu.caltech.cs2.helpers.Inspection;
 import edu.caltech.cs2.interfaces.IPriorityQueue;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Order;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.*;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.CsvSource;
 
@@ -17,6 +14,7 @@ import java.util.Random;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
 public class TopKSortTests {
     private static String STRING_SOURCE = "src/edu/caltech/cs2/sorts/TopKSort.java";
 
@@ -45,7 +43,7 @@ public class TopKSortTests {
     @Test
     @Tag("C")
     @Order(1)
-    @DisplayName("Sorting an empty array works as expected")
+    @DisplayName("Sorting an empty array does not fail")
     public void testEmptyArray() {
         IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[0];
         TopKSort.sort(array, 1);
@@ -65,6 +63,7 @@ public class TopKSortTests {
 
     @Test
     @Tag("C")
+    @Order(3)
     @DisplayName("K = 0 does not change the array")
     public void testZeroK() {
         IPriorityQueue.PQElement<Integer>[] array = new IPriorityQueue.PQElement[]{
@@ -78,6 +77,7 @@ public class TopKSortTests {
     }
 
     @Tag("C")
+    @Order(4)
     @ParameterizedTest(name = "Stress test TopKSort: size: {1}, k: {2}")
     @CsvSource({"42, 3000, 2000", "15, 5000, 1235", "20, 1000, 50"})
     @DisplayName("Stress test TopKSort")
-- 
GitLab