From e035a50580bb914ebc59e6e89ef0be4056ca75e3 Mon Sep 17 00:00:00 2001 From: Sander Ploegsma Date: Sun, 21 Jan 2024 15:59:00 +0100 Subject: [PATCH] Remove exercise analyzer unit tests --- src/test/java/analyzer/AnalyzerTest.java | 14 +---- .../exercises/GlobalAnalyzerTest.java | 4 +- .../hamming/HammingAnalyzerTest.java | 57 ------------------- .../exercises/twofer/TwoferAnalyzerTest.java | 50 ---------------- .../hamming/ConstructorTooLong.java.txt | 37 ------------ .../DoesNotThrowInConstructor.java.txt | 18 ------ .../exercises/hamming/MethodTooLong.java.txt | 41 ------------- .../MustUseCharAtOrCodePointAt.java.txt | 35 ------------ .../hamming/NestedCalculation.java.txt | 32 ----------- .../hamming/NestedValidation.java.txt | 53 ----------------- .../NoCalculationOfHammingDistance.java.txt | 30 ---------- .../NoConditionalInConstructor.java.txt | 14 ----- .../exercises/hamming/NoConstructor.java.txt | 15 ----- .../NoGetHammingDistanceMethod.java.txt | 6 -- .../exercises/hamming/NoHammingClass.java.txt | 4 -- ...lculationDelegatedFromConstructor.java.txt | 36 ------------ ...onDelegatedFromGetHammingDistance.java.txt | 40 ------------- ...thCalculationInGetHammingDistance.java.txt | 34 ----------- .../OptimalWithValidationMethod.java.txt | 32 ----------- .../hamming/ShouldUseStringIsEmpty.java.txt | 32 ----------- .../hamming/UsesCharacterLiterals.java.txt | 50 ---------------- .../hamming/UsesStreamReduce.java.txt | 34 ----------- .../twofer/HardCodedTestCases.java.txt | 15 ----- .../twofer/NoConditionalLogic.java.txt | 8 --- .../exercises/twofer/NoTwoferClass.java.txt | 4 -- .../exercises/twofer/NoTwoferMethod.java.txt | 6 -- .../exercises/twofer/Optimal.java.txt | 8 --- .../twofer/OptimalNoTernary.java.txt | 10 ---- .../exercises/twofer/UsesLambda.java.txt | 11 ---- .../exercises/twofer/UsesLoop.java.txt | 11 ---- .../twofer/UsesMultipleReturns.java.txt | 9 --- .../twofer/UsesStringFormat.java.txt | 8 --- 32 files changed, 4 insertions(+), 754 deletions(-) delete mode 100644 src/test/java/analyzer/exercises/hamming/HammingAnalyzerTest.java delete mode 100644 src/test/java/analyzer/exercises/twofer/TwoferAnalyzerTest.java delete mode 100644 src/test/resources/analyzer/exercises/hamming/ConstructorTooLong.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/DoesNotThrowInConstructor.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/MethodTooLong.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/MustUseCharAtOrCodePointAt.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/NestedCalculation.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/NestedValidation.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/NoCalculationOfHammingDistance.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/NoConditionalInConstructor.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/NoConstructor.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/NoGetHammingDistanceMethod.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/NoHammingClass.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromConstructor.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromGetHammingDistance.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationInGetHammingDistance.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/OptimalWithValidationMethod.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/ShouldUseStringIsEmpty.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/UsesCharacterLiterals.java.txt delete mode 100644 src/test/resources/analyzer/exercises/hamming/UsesStreamReduce.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/HardCodedTestCases.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/NoConditionalLogic.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/NoTwoferClass.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/NoTwoferMethod.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/Optimal.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/OptimalNoTernary.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/UsesLambda.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/UsesLoop.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/UsesMultipleReturns.java.txt delete mode 100644 src/test/resources/analyzer/exercises/twofer/UsesStringFormat.java.txt diff --git a/src/test/java/analyzer/AnalyzerTest.java b/src/test/java/analyzer/AnalyzerTest.java index 899653f6..fe6a312b 100644 --- a/src/test/java/analyzer/AnalyzerTest.java +++ b/src/test/java/analyzer/AnalyzerTest.java @@ -1,25 +1,15 @@ package analyzer; import com.github.javaparser.StaticJavaParser; -import com.github.javaparser.ast.CompilationUnit; import java.util.List; public abstract class AnalyzerTest { protected abstract Analyzer getAnalyzer(); - protected Analysis analyzeResourceFile(String resourceFileName) { - var resource = getClass().getResourceAsStream(resourceFileName); - return analyze(StaticJavaParser.parse(resource)); - } - - protected Analysis analyzeString(String javaCode) { - return analyze(StaticJavaParser.parse(javaCode)); - } - - private Analysis analyze(CompilationUnit compilationUnit) { + protected Analysis analyze(String javaCode) { var analysis = new Analysis(); - getAnalyzer().analyze(List.of(compilationUnit), analysis); + getAnalyzer().analyze(List.of(StaticJavaParser.parse(javaCode)), analysis); return analysis; } } diff --git a/src/test/java/analyzer/exercises/GlobalAnalyzerTest.java b/src/test/java/analyzer/exercises/GlobalAnalyzerTest.java index 33885058..bb81ee88 100644 --- a/src/test/java/analyzer/exercises/GlobalAnalyzerTest.java +++ b/src/test/java/analyzer/exercises/GlobalAnalyzerTest.java @@ -20,7 +20,7 @@ protected Analyzer getAnalyzer() { @MethodSource @ParameterizedTest public void solutionsWithMainMethod(String solution) { - var actual = analyzeString(solution); + var actual = analyze(solution); assertThat(actual.getComments()).contains(new DoNotUseMainMethod()); } @@ -44,7 +44,7 @@ public static void main(String[] args) {} @MethodSource @ParameterizedTest public void solutionsWithPrintStatements(String solution) { - var actual = analyzeString(solution); + var actual = analyze(solution); assertThat(actual.getComments()).contains(new AvoidPrintStatements()); } diff --git a/src/test/java/analyzer/exercises/hamming/HammingAnalyzerTest.java b/src/test/java/analyzer/exercises/hamming/HammingAnalyzerTest.java deleted file mode 100644 index 91bd901f..00000000 --- a/src/test/java/analyzer/exercises/hamming/HammingAnalyzerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package analyzer.exercises.hamming; - -import analyzer.Analyzer; -import analyzer.Comment; -import analyzer.AnalyzerTest; -import analyzer.comments.ConstructorTooLong; -import analyzer.comments.MethodTooLong; -import analyzer.comments.UseProperClassName; -import analyzer.comments.UseProperMethodName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; - -public class HammingAnalyzerTest extends AnalyzerTest { - @Override - protected Analyzer getAnalyzer() { - return new HammingAnalyzer(); - } - - private static Stream testCases() { - return Stream.of( - Arguments.of("NoHammingClass.java.txt", new Comment[]{new UseProperClassName("Hamming")}), - Arguments.of("NoGetHammingDistanceMethod.java.txt", new Comment[]{new UseProperMethodName("getHammingDistance")}), - Arguments.of("NoConstructor.java.txt", new Comment[]{new MustUseConstructor()}), - Arguments.of("NoConditionalInConstructor.java.txt", new Comment[]{new MustUseConditionalLogicInConstructor()}), - Arguments.of("DoesNotThrowInConstructor.java.txt", new Comment[]{new MustThrowInConstructor()}), - Arguments.of("NoCalculationOfHammingDistance.java.txt", new Comment[]{new MustCalculateHammingDistance()}), - Arguments.of("UsesCharacterLiterals.java.txt", new Comment[]{new AvoidCharacterLiterals()}), - Arguments.of("MustUseCharAtOrCodePointAt.java.txt", new Comment[]{new MustUseStringCharAtOrCodePointAt()}), - Arguments.of("NestedValidation.java.txt", new Comment[]{new CalculateDistanceInConstructor()}), - Arguments.of("NestedCalculation.java.txt", new Comment[0]), - Arguments.of("ShouldUseStringIsEmpty.java.txt", new Comment[]{new ShouldUseStringIsEmpty()}), - Arguments.of("OptimalWithCalculationInGetHammingDistance.java.txt", new Comment[]{new CalculateDistanceInConstructor()}), - Arguments.of("OptimalWithCalculationDelegatedFromGetHammingDistance.java.txt", new Comment[]{new CalculateDistanceInConstructor()}), - Arguments.of("ConstructorTooLong.java.txt", new Comment[]{new ConstructorTooLong("Hamming")}), - Arguments.of("MethodTooLong.java.txt", new Comment[]{new MethodTooLong("calculateHammingDistance")}), - Arguments.of("UsesStreamReduce.java.txt", new Comment[]{new ShouldUseStreamFilterAndCount()}), - Arguments.of("OptimalWithCalculationDelegatedFromConstructor.java.txt", new Comment[0]), - Arguments.of("OptimalWithValidationMethod.java.txt", new Comment[0])); - } - - @MethodSource("testCases") - @ParameterizedTest(name = "{0}") - public void testCommentsOnSolution(String solutionFile, Comment... expectedComments) { - var actual = analyzeResourceFile(getResourceFileName(solutionFile)); - - assertThat(actual.getComments()).containsExactly(expectedComments); - } - - private static String getResourceFileName(String testFileName) { - return "/analyzer/exercises/hamming/" + testFileName; - } -} diff --git a/src/test/java/analyzer/exercises/twofer/TwoferAnalyzerTest.java b/src/test/java/analyzer/exercises/twofer/TwoferAnalyzerTest.java deleted file mode 100644 index 594c8096..00000000 --- a/src/test/java/analyzer/exercises/twofer/TwoferAnalyzerTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package analyzer.exercises.twofer; - -import analyzer.Analyzer; -import analyzer.Comment; -import analyzer.AnalyzerTest; -import analyzer.comments.AvoidHardCodedTestCases; -import analyzer.comments.UseProperClassName; -import analyzer.comments.UseProperMethodName; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TwoferAnalyzerTest extends AnalyzerTest { - - @Override - protected Analyzer getAnalyzer() { - return new TwoferAnalyzer(); - } - - private static Stream testCases() { - return Stream.of( - Arguments.of("NoTwoferClass.java.txt", new Comment[]{new UseProperClassName("Twofer")}), - Arguments.of("NoTwoferMethod.java.txt", new Comment[]{new UseProperMethodName("twofer")}), - Arguments.of("UsesLambda.java.txt", new Comment[0]), - Arguments.of("UsesLoop.java.txt", new Comment[0]), - Arguments.of("HardCodedTestCases.java.txt", new Comment[]{new AvoidHardCodedTestCases()}), - Arguments.of("NoConditionalLogic.java.txt", new Comment[]{new UseConditionalLogic()}), - Arguments.of("UsesStringFormat.java.txt", new Comment[]{new AvoidStringFormat()}), - Arguments.of("UsesMultipleReturns.java.txt", new Comment[]{new UseOneReturn()}), - Arguments.of("OptimalNoTernary.java.txt", new Comment[]{new UseTernaryOperator()}), - Arguments.of("Optimal.java.txt", new Comment[0]) - ); - } - - @MethodSource("testCases") - @ParameterizedTest(name = "{0}") - public void testCommentsOnSolution(String solutionFile, Comment... expectedComments) { - var actual = analyzeResourceFile(getResourceFileName(solutionFile)); - - assertThat(actual.getComments()).containsExactly(expectedComments); - } - - private static String getResourceFileName(String testFileName) { - return "/analyzer/exercises/twofer/" + testFileName; - } -} diff --git a/src/test/resources/analyzer/exercises/hamming/ConstructorTooLong.java.txt b/src/test/resources/analyzer/exercises/hamming/ConstructorTooLong.java.txt deleted file mode 100644 index 822e460f..00000000 --- a/src/test/resources/analyzer/exercises/hamming/ConstructorTooLong.java.txt +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Optimal solution, but the constructor does too much. - * We use a simple heuristic based on line length. - */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - if (leftStrand.length() != rightStrand.length()) { - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int distance = 0; - - for (int i = 0; - i < leftStrand.length(); - i++) { - if (leftStrand.charAt(i) - != rightStrand.charAt(i)) { - distance++; - } - } - - hammingDistance = distance; - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/DoesNotThrowInConstructor.java.txt b/src/test/resources/analyzer/exercises/hamming/DoesNotThrowInConstructor.java.txt deleted file mode 100644 index 87e1870b..00000000 --- a/src/test/resources/analyzer/exercises/hamming/DoesNotThrowInConstructor.java.txt +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.stream.IntStream; - -/** Constructor must throw IllegalArgumentException. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - if (leftStrand.isEmpty()) { - this.hammingDistance = 0; - } else { - this.hammingDistance = 1; - } - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/MethodTooLong.java.txt b/src/test/resources/analyzer/exercises/hamming/MethodTooLong.java.txt deleted file mode 100644 index acde91b8..00000000 --- a/src/test/resources/analyzer/exercises/hamming/MethodTooLong.java.txt +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Optimal solution, but the helper method does too much. - * We use a simple heuristic based on line length. - */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - hammingDistance = calculateHammingDistance(leftStrand, rightStrand); - } - - private int calculateHammingDistance(String leftStrand, String rightStrand) { - if (leftStrand.length() != rightStrand.length()) { - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int distance = 0; - - for (int i = 0; - i < leftStrand.length(); - i++) { - if (leftStrand.charAt(i) - != rightStrand.charAt(i)) { - distance++; - } - } - - return distance; - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/MustUseCharAtOrCodePointAt.java.txt b/src/test/resources/analyzer/exercises/hamming/MustUseCharAtOrCodePointAt.java.txt deleted file mode 100644 index b7946ca6..00000000 --- a/src/test/resources/analyzer/exercises/hamming/MustUseCharAtOrCodePointAt.java.txt +++ /dev/null @@ -1,35 +0,0 @@ -import java.util.stream.IntStream; - -/** Optimal solution, but uses String.toCharArray. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - char[] left = leftStrand.toCharArray(); - char[] right = rightStrand.toCharArray(); - - hammingDistance = (int) IntStream.range(0, leftStrand.length()) - .filter(index -> left[index] != right[index]) - .count(); - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/NestedCalculation.java.txt b/src/test/resources/analyzer/exercises/hamming/NestedCalculation.java.txt deleted file mode 100644 index e8c2b161..00000000 --- a/src/test/resources/analyzer/exercises/hamming/NestedCalculation.java.txt +++ /dev/null @@ -1,32 +0,0 @@ -class Hamming { - - private int HammingDistance; - - Hamming(String leftStrand, String rightStrand) { - HammingDistance = calculateHammingDistance(leftStrand, rightStrand); - } - - private int calculateHammingDistance(String leftStrand, String rightStrand) { - int distance = 0; - - if (leftStrand.length() == rightStrand.length()) { - for (int i = 0; i < leftStrand.length(); i++) { - if (leftStrand.charAt(i) != rightStrand.charAt(i)) { - distance++; - } - } - } else if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } else if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } else { - throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length."); - } - return distance; - } - - int getHammingDistance() { - return HammingDistance; - } - -} diff --git a/src/test/resources/analyzer/exercises/hamming/NestedValidation.java.txt b/src/test/resources/analyzer/exercises/hamming/NestedValidation.java.txt deleted file mode 100644 index 43bd0a73..00000000 --- a/src/test/resources/analyzer/exercises/hamming/NestedValidation.java.txt +++ /dev/null @@ -1,53 +0,0 @@ -class Hamming { - - private String leftStrand; - private String rightStrand; - - Hamming(String leftStrand, String rightStrand) { - - validate(leftStrand, rightStrand); - this.leftStrand = leftStrand; - this.rightStrand = rightStrand; - } - - - private void validate(String leftStrand, String rightStrand) { - validateNotNull(leftStrand, rightStrand); - validateNotOneEmpty(leftStrand, rightStrand); - validateSameLength(leftStrand, rightStrand); - } - - private void validateNotNull(String leftStrand, String rightStrand) { - if (leftStrand == null || rightStrand == null) { - throw new IllegalArgumentException("Either left or right stand is null"); - } - } - - private void validateNotOneEmpty(String leftStrand, String rightStrand) { - if (leftStrand.isEmpty() && !rightStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } else if (!leftStrand.isEmpty() && rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - } - - private void validateSameLength(String leftStrand, String rightStrand) { - if (leftStrand.length() != rightStrand.length()) { - throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length."); - } - } - - int getHammingDistance() { - - int strandLen = this.leftStrand.length(); - int diffCount = 0; - for (int i = 0; i < strandLen; i++) { - if (this.leftStrand.charAt(i) != this.rightStrand.charAt(i)) { - diffCount++; - } - } - - return diffCount; - } - -} diff --git a/src/test/resources/analyzer/exercises/hamming/NoCalculationOfHammingDistance.java.txt b/src/test/resources/analyzer/exercises/hamming/NoCalculationOfHammingDistance.java.txt deleted file mode 100644 index 4a62b051..00000000 --- a/src/test/resources/analyzer/exercises/hamming/NoCalculationOfHammingDistance.java.txt +++ /dev/null @@ -1,30 +0,0 @@ -import java.util.stream.IntStream; - -/** Must actually calculate the hamming distance somewhere. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - hammingDistance = 0; - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/NoConditionalInConstructor.java.txt b/src/test/resources/analyzer/exercises/hamming/NoConditionalInConstructor.java.txt deleted file mode 100644 index 8d389c12..00000000 --- a/src/test/resources/analyzer/exercises/hamming/NoConditionalInConstructor.java.txt +++ /dev/null @@ -1,14 +0,0 @@ -import java.util.stream.IntStream; - -/** Constructor must have conditional logic. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - this.hammingDistance = 0; - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/NoConstructor.java.txt b/src/test/resources/analyzer/exercises/hamming/NoConstructor.java.txt deleted file mode 100644 index d38d1bb4..00000000 --- a/src/test/resources/analyzer/exercises/hamming/NoConstructor.java.txt +++ /dev/null @@ -1,15 +0,0 @@ -import java.util.stream.IntStream; - -/** Must use a custom constructor that takes two strings. */ -class Hamming { - private final int hammingDistance; - - /** Not the right type params. */ - Hamming(int hammingDistance) { - this.hammingDistance = hammingDistance; - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/NoGetHammingDistanceMethod.java.txt b/src/test/resources/analyzer/exercises/hamming/NoGetHammingDistanceMethod.java.txt deleted file mode 100644 index 56f8cbec..00000000 --- a/src/test/resources/analyzer/exercises/hamming/NoGetHammingDistanceMethod.java.txt +++ /dev/null @@ -1,6 +0,0 @@ -package analyzer.exercises.hamming; - -/** There must be a getHammingDistance method. */ -public class Hamming { - public void notGetHammingDistanceMethod() {} -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/NoHammingClass.java.txt b/src/test/resources/analyzer/exercises/hamming/NoHammingClass.java.txt deleted file mode 100644 index a2206578..00000000 --- a/src/test/resources/analyzer/exercises/hamming/NoHammingClass.java.txt +++ /dev/null @@ -1,4 +0,0 @@ -package analyzer.exercises.hamming; - -/** There must be a Hamming class. */ -public class NoHammingClass {} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromConstructor.java.txt b/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromConstructor.java.txt deleted file mode 100644 index bc0417cb..00000000 --- a/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromConstructor.java.txt +++ /dev/null @@ -1,36 +0,0 @@ -import java.util.stream.IntStream; - -/** Optimal solution with calculation delegated from constructor. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - hammingDistance = calculateDistance(leftStrand, rightStrand); - } - - private int calculateDistance(String leftStrand, String rightStrand) { - return (int) IntStream.range(0, leftStrand.length()) - .filter(index -> leftStrand.charAt(index) != rightStrand.charAt(index)) - .count(); - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromGetHammingDistance.java.txt b/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromGetHammingDistance.java.txt deleted file mode 100644 index 5e5e3802..00000000 --- a/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationDelegatedFromGetHammingDistance.java.txt +++ /dev/null @@ -1,40 +0,0 @@ -import java.util.stream.IntStream; - -/** Optimal solution with calculation delegated to getHammingDistance. */ -class Hamming { - private final String leftStrand; - private final String rightStrand; - private Integer hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - this.leftStrand = leftStrand; - this.rightStrand = rightStrand; - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - if (hammingDistance == null) hammingDistance = calculateDistance(); - return hammingDistance; - } - - private int calculateDistance() { - return (int) IntStream.range(0, leftStrand.length()) - .filter(index -> leftStrand.charAt(index) != rightStrand.charAt(index)) - .count(); - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationInGetHammingDistance.java.txt b/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationInGetHammingDistance.java.txt deleted file mode 100644 index 824f039c..00000000 --- a/src/test/resources/analyzer/exercises/hamming/OptimalWithCalculationInGetHammingDistance.java.txt +++ /dev/null @@ -1,34 +0,0 @@ -import java.util.stream.IntStream; - -/** Optimal solution with calculation in getHammingDistance. */ -class Hamming { - private final String leftStrand; - private final String rightStrand; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - this.leftStrand = leftStrand; - this.rightStrand = rightStrand; - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return (int) IntStream.range(0, leftStrand.length()) - .filter(index -> leftStrand.charAt(index) != rightStrand.charAt(index)) - .count(); - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/OptimalWithValidationMethod.java.txt b/src/test/resources/analyzer/exercises/hamming/OptimalWithValidationMethod.java.txt deleted file mode 100644 index 9bc80a49..00000000 --- a/src/test/resources/analyzer/exercises/hamming/OptimalWithValidationMethod.java.txt +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.stream.IntStream; - -/** Optimal solution using a method for validation. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - hammingDistance = (int) IntStream.range(0, leftStrand.length()) - .filter(index -> leftStrand.charAt(index) != rightStrand.charAt(index)) - .count(); - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/ShouldUseStringIsEmpty.java.txt b/src/test/resources/analyzer/exercises/hamming/ShouldUseStringIsEmpty.java.txt deleted file mode 100644 index 37b222ed..00000000 --- a/src/test/resources/analyzer/exercises/hamming/ShouldUseStringIsEmpty.java.txt +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.stream.IntStream; - -/** Optimal solution, but does not use String.isEmpty. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - hammingDistance = (int) IntStream.range(0, leftStrand.length()) - .filter(index -> leftStrand.charAt(index) != rightStrand.charAt(index)) - .count(); - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.length() == 0) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.length() == 0) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/UsesCharacterLiterals.java.txt b/src/test/resources/analyzer/exercises/hamming/UsesCharacterLiterals.java.txt deleted file mode 100644 index 2ab8373f..00000000 --- a/src/test/resources/analyzer/exercises/hamming/UsesCharacterLiterals.java.txt +++ /dev/null @@ -1,50 +0,0 @@ -import java.util.stream.IntStream; - -/** Should not be checking character literals. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - hammingDistance = calculateHammingDistance(leftStrand, rightStrand); - } - - private int calculateHammingDistance() { - return (int) IntStream.range(0, leftStrand.length()) - .filter(index -> nucleotidesDiffer(leftStrand.charAt(index), rightStrand.charAt(index))) - .count(); - } - - private boolean nucleotidesDiffer(char leftNucleotide, char rightNucleotide) { - switch (leftNucleotide) { - case 'C': - return rightNucleotide == 'A' || rightNucleotide == 'G' || rightNucleotide == 'T'; - case 'A': - return rightNucleotide == 'C' || rightNucleotide == 'G' || rightNucleotide == 'T'; - case 'G': - return rightNucleotide == 'A' || rightNucleotide == 'C' || rightNucleotide == 'T'; - case 'T': - return rightNucleotide == 'A' || rightNucleotide == 'G' || rightNucleotide == 'C'; - } - return false; // unknown nucleotide - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/hamming/UsesStreamReduce.java.txt b/src/test/resources/analyzer/exercises/hamming/UsesStreamReduce.java.txt deleted file mode 100644 index d65d872d..00000000 --- a/src/test/resources/analyzer/exercises/hamming/UsesStreamReduce.java.txt +++ /dev/null @@ -1,34 +0,0 @@ -import java.util.stream.IntStream; - -/** Optimal solution using a method for validation. */ -class Hamming { - private final int hammingDistance; - - Hamming(String leftStrand, String rightStrand) { - validateStrandsHaveEqualLength(leftStrand, rightStrand); - - hammingDistance = (int) IntStream.range(0, leftStrand.length()) - .reduce( - 0, - (acc, i) -> - (leftStrand.charAt(i) != rightStrand.charAt(i)) ? acc + 1 : acc); - } - - private void validateStrandsHaveEqualLength() { - if (leftStrand.length() == rightStrand.length()) { - return; - } - if (leftStrand.isEmpty()) { - throw new IllegalArgumentException("left strand must not be empty."); - } - if (rightStrand.isEmpty()) { - throw new IllegalArgumentException("right strand must not be empty."); - } - throw new IllegalArgumentException( - "leftStrand and rightStrand must be of equal length."); - } - - int getHammingDistance() { - return hammingDistance; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/HardCodedTestCases.java.txt b/src/test/resources/analyzer/exercises/twofer/HardCodedTestCases.java.txt deleted file mode 100644 index e3945ce5..00000000 --- a/src/test/resources/analyzer/exercises/twofer/HardCodedTestCases.java.txt +++ /dev/null @@ -1,15 +0,0 @@ -package analyzer.exercises.twofer; - -/** Cannot hard-code the strings. */ -public class Twofer { - public String twofer(String name) { - if (name == null) { - // fall through - } else if (name.equals("Alice")) { - return "One for Alice, one for me."; - } else if (name.equals("Bob")) { - return "One for Bob, one for me."; - } - return "One for you, one for me."; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/NoConditionalLogic.java.txt b/src/test/resources/analyzer/exercises/twofer/NoConditionalLogic.java.txt deleted file mode 100644 index e187582a..00000000 --- a/src/test/resources/analyzer/exercises/twofer/NoConditionalLogic.java.txt +++ /dev/null @@ -1,8 +0,0 @@ -package analyzer.exercises.twofer; - -/** Missing necessary conditional logic. */ -public class Twofer { - public String twofer(String name) { - return "One for you, one for me."; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/NoTwoferClass.java.txt b/src/test/resources/analyzer/exercises/twofer/NoTwoferClass.java.txt deleted file mode 100644 index 583d314e..00000000 --- a/src/test/resources/analyzer/exercises/twofer/NoTwoferClass.java.txt +++ /dev/null @@ -1,4 +0,0 @@ -package analyzer.exercises.twofer; - -/** Empty class for testing that the class must be named correctly. */ -public class NoTwoferClass {} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/NoTwoferMethod.java.txt b/src/test/resources/analyzer/exercises/twofer/NoTwoferMethod.java.txt deleted file mode 100644 index 698a7265..00000000 --- a/src/test/resources/analyzer/exercises/twofer/NoTwoferMethod.java.txt +++ /dev/null @@ -1,6 +0,0 @@ -package analyzer.exercises.twofer; - -/** Empty class for testing that there must be a twofer method. */ -public class Twofer { - public void notTwoferMethod() {} -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/Optimal.java.txt b/src/test/resources/analyzer/exercises/twofer/Optimal.java.txt deleted file mode 100644 index 4c4e95a1..00000000 --- a/src/test/resources/analyzer/exercises/twofer/Optimal.java.txt +++ /dev/null @@ -1,8 +0,0 @@ -package analyzer.exercises.twofer; - -/** Optimal solution. */ -public class Twofer { - public String twofer(String rawName) { - return "One for " + name == null ? "you" : name + ", one for me."; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/OptimalNoTernary.java.txt b/src/test/resources/analyzer/exercises/twofer/OptimalNoTernary.java.txt deleted file mode 100644 index 27294dcb..00000000 --- a/src/test/resources/analyzer/exercises/twofer/OptimalNoTernary.java.txt +++ /dev/null @@ -1,10 +0,0 @@ -package analyzer.exercises.twofer; - -/** Better to use ternary over an if statement. */ -public class Twofer { - public String twofer(String rawName) { - String name = rawName; - if (name == null) name = "you"; - return "One for " + name + ", one for me."; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/UsesLambda.java.txt b/src/test/resources/analyzer/exercises/twofer/UsesLambda.java.txt deleted file mode 100644 index d66b75fb..00000000 --- a/src/test/resources/analyzer/exercises/twofer/UsesLambda.java.txt +++ /dev/null @@ -1,11 +0,0 @@ -package analyzer.exercises.twofer; - -/** Using lambdas probably deserves a mentor review. */ -public class Twofer { - public String twofer(String name) { - Predicate isNull = s -> s == null; - if (isNull.test(name)) - return "One for you, one for me."; - return "One for " + name + ", one for me."; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/UsesLoop.java.txt b/src/test/resources/analyzer/exercises/twofer/UsesLoop.java.txt deleted file mode 100644 index 76b9a315..00000000 --- a/src/test/resources/analyzer/exercises/twofer/UsesLoop.java.txt +++ /dev/null @@ -1,11 +0,0 @@ -package analyzer.exercises.twofer; - -/** Using loops deserves mentor review. */ -public class Twofer { - public String twofer(String name) { - for (int i = 0; i < 10; i++) { - // noop - } - return "One for " + name + ", one for me."; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/UsesMultipleReturns.java.txt b/src/test/resources/analyzer/exercises/twofer/UsesMultipleReturns.java.txt deleted file mode 100644 index 81e2b648..00000000 --- a/src/test/resources/analyzer/exercises/twofer/UsesMultipleReturns.java.txt +++ /dev/null @@ -1,9 +0,0 @@ -package analyzer.exercises.twofer; - -/** Multiple returns are unnecessary. */ -public class Twofer { - public String twofer(String name) { - if (name == null) return "One for you, one for me."; - return "One for " + name + ", one for me."; - } -} \ No newline at end of file diff --git a/src/test/resources/analyzer/exercises/twofer/UsesStringFormat.java.txt b/src/test/resources/analyzer/exercises/twofer/UsesStringFormat.java.txt deleted file mode 100644 index bec68090..00000000 --- a/src/test/resources/analyzer/exercises/twofer/UsesStringFormat.java.txt +++ /dev/null @@ -1,8 +0,0 @@ -package analyzer.exercises.twofer; - -/** String.format is too slow. */ -public class Twofer { - public String twofer(String name) { - return String.format("One for %s, one for me.", name == null ? "you" : name); - } -} \ No newline at end of file