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 527714b30d5935d086ec772645862f96a11c8e93..0000000000000000000000000000000000000000 --- 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 4de9727c9a46ef0c9081e4ecd247aa87400cc1a6..0000000000000000000000000000000000000000 --- 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 2d96221dd7e287091a5417b9880c0c466083a513..0000000000000000000000000000000000000000 --- 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/misc.xml b/.idea/misc.xml index 84856164cee5ca1348f6ad91c34cf3b95797f714..dd4cca36cc86be0457f3f3910eb0f257e10732a4 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 828ccae0200a5a64931454368b3d5069c4460120..ff5d7e34add5d034560d807d6342a1553f1f18e1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,100 +2,18 @@ <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/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$/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$/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/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> - <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 +22,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,8 +73,21 @@ </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="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,6 +145,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 +297,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 +309,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="last_opened_file_path" value="$PROJECT_DIR$/src/edu/caltech/cs2/datastructures" /> <property name="project.structure.last.edited" value="Libraries" /> <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,75 +332,130 @@ <recent name="$PROJECT_DIR$/src/beaverchat/css" /> <recent name="$PROJECT_DIR$/data/possible_corrections" /> </key> + <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="RunDashboard"> - <option name="ruleStates"> - <list> - <RuleState> - <option name="name" value="ConfigurationTypeDashboardGroupingRule" /> - </RuleState> - <RuleState> - <option name="name" value="StatusDashboardGroupingRule" /> - </RuleState> - </list> - </option> - </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=""Anirudh Mathukumilli" $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"> @@ -564,19 +463,26 @@ </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> + <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SvnConfiguration"> <configuration /> </component> @@ -833,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"> @@ -932,12 +859,22 @@ <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 The spell check now computes all possible words of edit distance two. All that remains is choosing the most likely one." /> <MESSAGE value="Finish implementing spelling correction. Now I just have to write a bunch of tests. I did finish the NGramMap tests." /> <MESSAGE value="Implement getBestSuggestion I now have a function that will return the top suggestion in the ngrams map." /> <MESSAGE value="Finish getPossibleCorrectionsTest I now have a test that checks whether or not students are correctly retrieving all possible corrections." /> @@ -962,21 +899,20 @@ <MESSAGE value="Flesh out spec The spec now fully fleshes out all of the students' tasks Edit distance is still horribly explained, but I cannot seem to make it better Spec is ugly; needs some serious formatting love" /> <MESSAGE value="Move chat files around Chat web client files were thrown around everywhere, so I consolidated them" /> <MESSAGE value="Clean up js Mostly just commented and moved around js so it wasn't so messy. Could definitely be improved, but js is not my forte" /> - <option name="LAST_COMMIT_MESSAGE" value="Clean up js Mostly just commented and moved around js so it wasn't so 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> - <properties /> + <line>43</line> <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/project06-beaverchat.iml b/project06-beaverchat.iml index e238e70946155eaff66193ae7de15420aed2ac71..bbfc5779730384e6f9542c385e006d1249ce50a9 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 7c398851c2c68f800fc21df9de2d2589780697e3..7e91ff5f9c96b14a0e77fdc09b3d4aec1e8a6695 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/IDeque.java b/src/edu/caltech/cs2/interfaces/IDeque.java index 3b8f87ac5ff118d9a1628f39b8a6fab7c6324f5d..4adba8ff4a79547a42ea8aef471a24077b1c9827 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 64650804a3cc4bcb7e86e73c8a8b251c60fab1b7..d04d3f34ba47f8e3e7aae41304c2ea7e851b805a 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 b91345d7c21c294455b5b36dc7d8ea56760254fb..0000000000000000000000000000000000000000 --- 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/interfaces/IPriorityQueue.java b/src/edu/caltech/cs2/interfaces/IPriorityQueue.java index a2ea84aaecd04c1c1982c8a3b19bdd0bef9c48dd..721b3ad3383086ad731fe25f3baf91df27c375b4 100644 --- a/src/edu/caltech/cs2/interfaces/IPriorityQueue.java +++ b/src/edu/caltech/cs2/interfaces/IPriorityQueue.java @@ -2,15 +2,15 @@ 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>> { 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; } @@ -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/src/edu/caltech/cs2/types/NGram.java b/src/edu/caltech/cs2/types/NGram.java index 24b324e5c36af5f5d4fa64511a7608a9a1aa0064..8b0b57c147a7e66bf84783c4d8b70ddc1fbec69f 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/src/wordsuggestor/ParseFBMessages.java b/src/wordsuggestor/ParseFBMessages.java index 5499d9d1c149c6b70c3a078bfa9496da73bc4298..889d91aa9e5686352be4ecc247948e2b5c13e791 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/HeapTester.java b/tests/edu/caltech/cs2/datastructures/HeapTester.java deleted file mode 100644 index a7ada1b93f8b4304c3491125eae3f66457aea056..0000000000000000000000000000000000000000 --- a/tests/edu/caltech/cs2/datastructures/HeapTester.java +++ /dev/null @@ -1,238 +0,0 @@ -package edu.caltech.cs2.datastructures; - -import edu.caltech.cs2.helpers.Inspection; -import edu.caltech.cs2.helpers.Reflection; - -import java.util.*; -import java.util.ArrayList; - -import edu.caltech.cs2.interfaces.IPriorityQueue; -import edu.caltech.cs2.misc.IntegerComparator; -import org.junit.jupiter.api.*; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; - -import static org.junit.jupiter.api.Assertions.*; - -public class HeapTester { - private static String STRING_SOURCE = "src/edu/caltech/cs2/datastructures/MinFourHeap.java"; - - @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"); - 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" - )); - } - - @Test - @Tag("C") - public void testDuplicateThrows() { - MinFourHeap<Integer> heap = new MinFourHeap<>(); - heap.enqueue(new IPriorityQueue.PQElement(10, 10)); - assertThrows(IllegalArgumentException.class, () -> { - heap.enqueue(new IPriorityQueue.PQElement(10, 10)); - }); - } - - @Test - @Tag("C") - public void testIdxTooLargeThrows() { - Comparator<Integer> c = new IntegerComparator(); - MinFourHeap<Integer> heap = new MinFourHeap<>(); - heap.enqueue(new IPriorityQueue.PQElement<>(10, 10)); - assertThrows(IllegalArgumentException.class, () -> { - heap.increaseKey(new IPriorityQueue.PQElement<>(11, 11)); - }); - assertThrows(IllegalArgumentException.class, () -> { - heap.decreaseKey(new IPriorityQueue.PQElement<>(11, 11)); - }); - } - - @Test - @Tag("C") - public void testEnqueue() { - // create heap - MinFourHeap<Integer> heap = new MinFourHeap<>(); - List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70)); - - // step by step look at what heap internal data array should look like - List<List<Integer>> step_by_step = new ArrayList<>(); - step_by_step.add(Arrays.asList(9)); - step_by_step.add(Arrays.asList(-100, 9)); - step_by_step.add(Arrays.asList(-100, 9, 19)); - step_by_step.add(Arrays.asList(-100, 9, 19, 3)); - step_by_step.add(Arrays.asList(-100, 9, 19, 3, -2)); - step_by_step.add(Arrays.asList(-100, 1, 19, 3, -2, 9)); - step_by_step.add(Arrays.asList(-100, 1, 19, 3, -2, 9, 7)); - step_by_step.add(Arrays.asList(-100, -84, 19, 3, -2, 9, 7, 1)); - step_by_step.add(Arrays.asList(-100, -84, 19, 3, -2, 9, 7, 1, -4)); - step_by_step.add(Arrays.asList(-100, -84, 2, 3, -2, 9, 7, 1, -4, 19)); - step_by_step.add(Arrays.asList(-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70)); - - // enqueue values while examining internal state - for (int i = 0; i < values.size(); i++) { - 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); - for(int j = 0; j < heap.size(); j++) { - assertEquals(step_by_step.get(i).toArray()[j], heap_data[j].data); - } - } - } - - @Test - @Tag("C") - 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 i = 0; i < reference.size(); i++) { - assertEquals(reference.remove(), heap.dequeue().data); - assertEquals(reference.size(), heap.size()); - } - - } - - @Tag("C") - @ParameterizedTest(name = "Stress test enqueue and dequeue.") - @CsvSource({ - "100, 3000", "42, 1000" - }) - 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))); - assertEquals(heap.size(), reference.size()); - } - while (heap.size() != 0) { - assertEquals(heap.dequeue().data, reference.remove()); - } - } - - @Test - @Tag("C") - public void testIncreaseKey() { - 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)))); - } - 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++) { - 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}; - heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap); - for (int i = 0; i < heap.size(); i++) { - assertEquals(correctHeapAfterIncrease[i], heap_data[i].priority); - } - } - - @Test - @Tag("C") - 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)))); - } - 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++) { - 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}; - heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap); - for (int i = 0; i < heap.size(); i++) { - assertEquals(correctHeapAfterDecrease[i], heap_data[i].priority); - } - } - - @Tag("C") - @ParameterizedTest(name = "Stress test increase/decrease key") - @CsvSource({ - "100, 3000, 1500", "42, 1000, 500" - }) - public void stressTestIncreaseDecrease(int seed, int size, int numToReplace) { - MinFourHeap<Integer> heap = new MinFourHeap<>(); - Comparator<Integer> c = new IntegerComparator(); - PriorityQueue<Integer> reference = new PriorityQueue<>(c); - Set<Integer> removed = new TreeSet<>(); - 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); - heap.enqueue(new IPriorityQueue.PQElement<>(num, num)); - assertEquals(reference.size(), heap.size()); - } - - for (int j = 0; j < numToReplace; j++) { - int newKey = r.nextInt(); - while (reference.contains(newKey) || removed.contains(newKey)) { - newKey = r.nextInt(); - } - IPriorityQueue.PQElement[] heap_data = Reflection.getFieldValue(MinFourHeap.class, "data", heap); - int idx = r.nextInt(heap.size()); - Integer origKey = (Integer)heap_data[idx].data; - while (removed.contains(origKey)) { - idx = r.nextInt(heap.size()); - origKey = (Integer)heap_data[idx].data; - } - if (newKey < origKey) { - heap.decreaseKey(new IPriorityQueue.PQElement(origKey, newKey)); - } - else { - heap.increaseKey(new IPriorityQueue.PQElement(origKey, newKey)); - } - assertEquals(reference.size(), heap.size()); - removed.add(origKey); - reference.remove(origKey); - reference.add(newKey); - assertEquals(reference.size(), heap.size()); - } - - while(!reference.isEmpty()) { - Integer er = reference.remove(); - IPriorityQueue.PQElement mr = heap.dequeue(); - assertEquals(er, mr.priority); - } - - } -} \ No newline at end of file diff --git a/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java new file mode 100644 index 0000000000000000000000000000000000000000..2ccb962f41fcade157c89186b55d2665d46aa03b --- /dev/null +++ b/tests/edu/caltech/cs2/datastructures/MinFourHeapTests.java @@ -0,0 +1,349 @@ +package edu.caltech.cs2.datastructures; + +import edu.caltech.cs2.helpers.Inspection; +import edu.caltech.cs2.helpers.Reflection; + +import java.util.*; +import java.util.ArrayList; + +import edu.caltech.cs2.interfaces.IDictionary; +import edu.caltech.cs2.interfaces.IPriorityQueue; +import edu.caltech.cs2.misc.IntegerComparator; +import org.junit.jupiter.api.*; +import org.junit.jupiter.params.ParameterizedTest; +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.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")); + } + + @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)); + assertThrows(IllegalArgumentException.class, () -> { + heap.enqueue(new IPriorityQueue.PQElement<>(10, 10)); + }); + } + + @Test + @Tag("C") + @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, () -> { + heap.increaseKey(new IPriorityQueue.PQElement<>(11, 11)); + }); + assertThrows(IllegalArgumentException.class, () -> { + heap.decreaseKey(new IPriorityQueue.PQElement<>(11, 11)); + }); + } + + @Test + @Tag("C") + @Order(4) + @DisplayName("Smoke test enqueue while checking internal state of heap") + public void testEnqueue() { + // create heap + MinFourHeap<Integer> heap = new MinFourHeap<>(); + List<Integer> values = new ArrayList<>(Arrays.asList(9, -100, 19, 3, -2, 1, 7, -84, -4, 2, 70)); + + // step by step look at what heap internal data array should look like + List<List<Integer>> step_by_step = new ArrayList<>(); + step_by_step.add(Arrays.asList(9)); + step_by_step.add(Arrays.asList(-100, 9)); + step_by_step.add(Arrays.asList(-100, 9, 19)); + step_by_step.add(Arrays.asList(-100, 9, 19, 3)); + step_by_step.add(Arrays.asList(-100, 9, 19, 3, -2)); + step_by_step.add(Arrays.asList(-100, 1, 19, 3, -2, 9)); + step_by_step.add(Arrays.asList(-100, 1, 19, 3, -2, 9, 7)); + step_by_step.add(Arrays.asList(-100, -84, 19, 3, -2, 9, 7, 1)); + step_by_step.add(Arrays.asList(-100, -84, 19, 3, -2, 9, 7, 1, -4)); + step_by_step.add(Arrays.asList(-100, -84, 2, 3, -2, 9, 7, 1, -4, 19)); + step_by_step.add(Arrays.asList(-100, -84, 2, 3, -2, 9, 7, 1, -4, 19, 70)); + + // enqueue values while examining internal state + for (int i = 0; i < values.size(); i++) { + assertTrue(heap.enqueue(new IPriorityQueue.PQElement<>(values.get(i), values.get(i)))); + assertEquals(i + 1, heap.size()); + + 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], heapData[j].data); + } + + checkKeyToIndexMap(heap); + } + } + + @Test + @Tag("C") + @Order(4) + @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 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); + checkKeyToIndexMap(heap); + assertEquals(reference.size(), heap.size()); + } + } + + @Test + @Tag("C") + @Order(5) + @DisplayName("Smoke test increaseKey while checking internal state of heap") + public void testIncreaseKey() { + // 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>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); + for (int j = 0; j < heap.size(); j++) { + 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}; + heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); + checkKeyToIndexMap(heap); + for (int i = 0; i < heap.size(); i++) { + assertEquals(correctHeapPrioritiesAfterIncrease[i], heapData[i].priority); + } + } + + @Test + @Tag("C") + @Order(5) + @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>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); + for (int j = 0; j < heap.size(); j++) { + 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}; + heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); + checkKeyToIndexMap(heap); + for (int i = 0; i < heap.size(); i++) { + assertEquals(correctHeapPrioritiesAfterDecrease[i], heapData[i].priority); + } + } + + @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 + @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<>(); + Comparator<Integer> c = new IntegerComparator(); + PriorityQueue<Integer> reference = new PriorityQueue<>(c); + Set<Integer> removed = new TreeSet<>(); + 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); + heap.enqueue(new IPriorityQueue.PQElement<>(num, num)); + assertEquals(reference.size(), heap.size()); + } + + for (int j = 0; j < numToReplace; j++) { + int newPriority = r.nextInt(); + while (reference.contains(newPriority) || removed.contains(newPriority)) { + newPriority = r.nextInt(); + } + IPriorityQueue.PQElement<Integer>[] heapData = Reflection.getFieldValue(MinFourHeap.class, "data", heap); + Integer origKey = heapData[r.nextInt(heap.size())].data; + while (removed.contains(origKey)) { + origKey = heapData[r.nextInt(heap.size())].data; + } + if (newPriority < origKey) { + heap.decreaseKey(new IPriorityQueue.PQElement<>(origKey, newPriority)); + } else { + heap.increaseKey(new IPriorityQueue.PQElement<>(origKey, newPriority)); + } + assertEquals(reference.size(), heap.size()); + removed.add(origKey); + reference.remove(origKey); + reference.add(newPriority); + assertEquals(reference.size(), heap.size()); + } + int i = 0; + while (!reference.isEmpty()) { + Integer er = reference.remove(); + IPriorityQueue.PQElement<Integer> mr = heap.dequeue(); + if (er != mr.priority) { + System.err.println(i); + System.err.println(reference.size()); + System.err.println(heap.size()); + } + 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/datastructures/NGramMapTests.java b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java index 854b89e566602642232210bb66d31d1e32a76bff..616ca8405e650a64b38efd275e1043d38ce80672 100644 --- a/tests/edu/caltech/cs2/datastructures/NGramMapTests.java +++ b/tests/edu/caltech/cs2/datastructures/NGramMapTests.java @@ -1,22 +1,18 @@ 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; -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; -import java.util.function.Function; 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,32 +21,36 @@ 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.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 = (IDeque<String> x) -> new NGram(x); - 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); + 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); } @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); @@ -62,6 +62,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); @@ -73,6 +75,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"))); @@ -80,6 +84,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); @@ -95,8 +101,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); } @@ -105,6 +110,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); @@ -112,6 +119,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 +132,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/helpers/Inspection.java b/tests/edu/caltech/cs2/helpers/Inspection.java index cdf089ea1d4d71a1d5df3970aedf8cf1e6181502..c3f1fca907bf0c2663ab184651e96f6b432eb46c 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++; } diff --git a/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java b/tests/edu/caltech/cs2/project06/SpellingCorrectorTests.java index 38c37ce24bd7b39ff3216cdb5636dfec4052156d..a6500130b600cb428b040234a1be8366bcce095a 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; @@ -18,12 +15,12 @@ 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.*; +@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 +36,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 = (IDeque<String> x) -> new NGram(x); - 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 +61,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 +83,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 +124,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 +151,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 50% rename from tests/edu/caltech/cs2/sorts/SortTester.java rename to tests/edu/caltech/cs2/sorts/TopKSortTests.java index 91d7eb0200486133b68e36d9031546fe1958b0b3..765574dcc37858f1cbfe2d5f6d4b543a478eab7e 100644 --- a/tests/edu/caltech/cs2/sorts/SortTester.java +++ b/tests/edu/caltech/cs2/sorts/TopKSortTests.java @@ -2,11 +2,7 @@ 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; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -18,7 +14,8 @@ import java.util.Random; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -public class SortTester { +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class TopKSortTests { private static String STRING_SOURCE = "src/edu/caltech/cs2/sorts/TopKSort.java"; @Order(0) @@ -26,25 +23,39 @@ 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 does not fail") 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); } @Test @Tag("C") + @Order(2) + @DisplayName("K < 0 throws an exception") 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); }); @@ -52,14 +63,13 @@ public class SortTester { @Test @Tag("C") + @Order(3) + @DisplayName("K = 0 does not change the array") 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]; @@ -67,26 +77,26 @@ public class SortTester { } @Tag("C") + @Order(4) @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"}) + @DisplayName("Stress test TopKSort") 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 = Comparator.comparingDouble(x -> x.priority); Random r = new Random(seed); Integer[] intarray = r.ints(size).boxed().toArray(Integer[]::new); - IPriorityQueue.PQElement[] array = new IPriorityQueue.PQElement[intarray.length]; + Double[] doublearray = Arrays.stream(intarray).map(Double::valueOf).toArray(Double[]::new); + IPriorityQueue.PQElement<Integer>[] 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); - 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]; - } - else { + } else { correct[i] = null; } }