Commit 7132f581 authored by Ethan Ordentlich's avatar Ethan Ordentlich
Browse files

Small clean-up changes

- Fix ChainingHash import tests
- Fix ChainingHash growth test OOM risk
- Add timeouts to complexity tests
parent 749c1ba2
No related merge requests found
Showing with 66 additions and 10 deletions
+66 -10
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ChainingHashDictionaryTests" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="project05-markov" />
<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.ChainingHashDictionaryTests" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MoveToFrontDictionaryTests" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="project05-markov" />
<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.MoveToFrontDictionaryTests" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="NGramTests" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="project05-markov" />
<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.NGramTests" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
...@@ -61,7 +61,7 @@ public class ChainingHashDictionaryTests implements IDictionaryNGramTests { ...@@ -61,7 +61,7 @@ public class ChainingHashDictionaryTests implements IDictionaryNGramTests {
@DisplayName("Does not use or import disallowed classes from java.util") @DisplayName("Does not use or import disallowed classes from java.util")
@Test @Test
public void testForInvalidImportsJavaUtil() { public void testForInvalidImportsJavaUtil() {
List<String> allowed = List.of("Iterator", "Supplier", "Stream"); List<String> allowed = List.of("Iterator", "function\\.Supplier", "stream\\.Stream");
Inspection.assertNoImportsOfExcept(DICTIONARY_SOURCE, "java\\.util", allowed); Inspection.assertNoImportsOfExcept(DICTIONARY_SOURCE, "java\\.util", allowed);
List<String> bannedUsages = List.of("java\\.util\\.(?!" + String.join("|", allowed) + ")"); List<String> bannedUsages = List.of("java\\.util\\.(?!" + String.join("|", allowed) + ")");
...@@ -94,14 +94,12 @@ public class ChainingHashDictionaryTests implements IDictionaryNGramTests { ...@@ -94,14 +94,12 @@ public class ChainingHashDictionaryTests implements IDictionaryNGramTests {
@Timeout(value = 20, unit = SECONDS) @Timeout(value = 20, unit = SECONDS)
@Test @Test
public void testGrowthCapability() { public void testGrowthCapability() {
Set<IDictionary<Object, Object>> dicts = new HashSet<>(); for (int i = 0; i < 25; i++) {
for (int i = 0; i < 50; i++) { IDictionary<Object, Object> dict = new ChainingHashDictionary<>(MoveToFrontDictionary::new);
dicts.add(new ChainingHashDictionary<>(MoveToFrontDictionary::new)); for (int j = 0; j < 500000; j++) {
} dict.put(j, j);
for (IDictionary<Object, Object> dict : dicts) {
for (int i = 0; i < 400000; i++) {
dict.put(i, i);
} }
// This _should_ get GC'd with a smaller heap size...
} }
} }
......
...@@ -6,6 +6,7 @@ import edu.caltech.cs2.textgenerator.NGram; ...@@ -6,6 +6,7 @@ import edu.caltech.cs2.textgenerator.NGram;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import java.util.HashMap; import java.util.HashMap;
...@@ -17,6 +18,7 @@ import java.util.stream.Stream; ...@@ -17,6 +18,7 @@ import java.util.stream.Stream;
import static edu.caltech.cs2.project05.Project05TestOrdering.sanityTestLevel; import static edu.caltech.cs2.project05.Project05TestOrdering.sanityTestLevel;
import static edu.caltech.cs2.project05.Project05TestOrdering.specialTestLevel; import static edu.caltech.cs2.project05.Project05TestOrdering.specialTestLevel;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
// Wrapper class for all IDictionaries that will be tested using NGram keys to reduce code repetition // Wrapper class for all IDictionaries that will be tested using NGram keys to reduce code repetition
...@@ -47,7 +49,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests { ...@@ -47,7 +49,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests {
@Override @Override
default Map<Object, Object> generateRandomTestData(int size, Random rand, int maxNodeDegree, int minKeyLength, default Map<Object, Object> generateRandomTestData(int size, Random rand, int maxNodeDegree, int minKeyLength,
int maxKeyLength) { int maxKeyLength) {
Map<Object, Object> base = new HashMap<>(); Map<Object, Object> base = new HashMap<>();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int keyLength = minKeyLength + rand.nextInt(maxKeyLength - minKeyLength); int keyLength = minKeyLength + rand.nextInt(maxKeyLength - minKeyLength);
...@@ -77,6 +79,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests { ...@@ -77,6 +79,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests {
@Order(specialTestLevel) @Order(specialTestLevel)
@DisplayName("Test get() -- complexity") @DisplayName("Test get() -- complexity")
@Test @Test
@Timeout(value = 20, unit = SECONDS)
default void testGetComplexity() { default void testGetComplexity() {
Function<Integer, IDictionary<Object, Object>> provide = (Integer numElements) -> { Function<Integer, IDictionary<Object, Object>> provide = (Integer numElements) -> {
IDictionary<Object, Object> t = newIDictionary(); IDictionary<Object, Object> t = newIDictionary();
...@@ -95,6 +98,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests { ...@@ -95,6 +98,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests {
@Order(specialTestLevel) @Order(specialTestLevel)
@DisplayName("Test put() -- complexity") @DisplayName("Test put() -- complexity")
@Test @Test
@Timeout(value = 20, unit = SECONDS)
default void testPutComplexity() { default void testPutComplexity() {
Function<Integer, IDictionary<Object, Object>> provide = (Integer numElements) -> { Function<Integer, IDictionary<Object, Object>> provide = (Integer numElements) -> {
IDictionary<Object, Object> t = newIDictionary(); IDictionary<Object, Object> t = newIDictionary();
...@@ -113,6 +117,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests { ...@@ -113,6 +117,7 @@ public interface IDictionaryNGramTests extends IDictionaryTests {
@Order(specialTestLevel) @Order(specialTestLevel)
@DisplayName("Test size() -- complexity") @DisplayName("Test size() -- complexity")
@Test @Test
@Timeout(value = 20, unit = SECONDS)
default void testSizeComplexity() { default void testSizeComplexity() {
Function<Integer, IDictionary<Object, Object>> provide = (Integer numElements) -> { Function<Integer, IDictionary<Object, Object>> provide = (Integer numElements) -> {
IDictionary<Object, Object> t = newIDictionary(); IDictionary<Object, Object> t = newIDictionary();
......
...@@ -96,7 +96,6 @@ public class MoveToFrontDictionaryTests implements IDictionaryNGramTests { ...@@ -96,7 +96,6 @@ public class MoveToFrontDictionaryTests implements IDictionaryNGramTests {
} }
} }
// TODO: what the fuck
@Order(classSpecificTestLevel) @Order(classSpecificTestLevel)
@DisplayName("Check MoveToFrontDictionary class is properly implemented") @DisplayName("Check MoveToFrontDictionary class is properly implemented")
@Test @Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment