-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add unit tests for LeapAnalyzer * Add test coverage reporting * Add coverage badge to README
- Loading branch information
1 parent
73b09c9
commit ef2c44f
Showing
23 changed files
with
76 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package analyzer.exercises.leap; | ||
|
||
import analyzer.AnalyzerTest; | ||
import analyzer.Comment; | ||
import analyzer.comments.AvoidHardCodedTestCases; | ||
import org.junit.jupiter.api.Test; | ||
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 LeapAnalyzerTest extends AnalyzerTest<LeapAnalyzer> { | ||
private static final String RESOURCE_LOCATION = "/analyzer/exercises/leap/"; | ||
|
||
public LeapAnalyzerTest() { | ||
super(LeapAnalyzer.class); | ||
} | ||
|
||
@Test | ||
public void optimalSolution() { | ||
var analysis = analyzeResourceFile(RESOURCE_LOCATION + "OptimalSolution.java"); | ||
assertThat(analysis.getComments()).isEmpty(); | ||
} | ||
|
||
private static Stream<Arguments> testCases() { | ||
return Stream.of( | ||
Arguments.of("HardCodedTestCases.java", new AvoidHardCodedTestCases()), | ||
Arguments.of("UsingGregorianCalendar.java", new NoBuiltInMethods()), | ||
Arguments.of("UsingIfStatements.java", new AvoidConditionalLogic()), | ||
Arguments.of("UsingJavaTime.java", new NoBuiltInMethods()), | ||
Arguments.of("UsingTernary.java", new AvoidConditionalLogic()), | ||
Arguments.of("UsingTooManyChecks.java", new UseMinimumNumberOfChecks()) | ||
); | ||
} | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@MethodSource("testCases") | ||
public void testCommentsOnSolution(String filename, Comment expectedComment) { | ||
var analysis = analyzeResourceFile(RESOURCE_LOCATION + filename); | ||
assertThat(analysis.getComments()).contains(expectedComment); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/analyzer/exercises/leap/HardCodedTestCases.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Leap { | ||
boolean isLeapYear(int year) { | ||
return year == 1960 || year == 2000 || year == 2400 || year == 1996; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/analyzer/exercises/leap/OptimalSolution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Leap { | ||
boolean isLeapYear(int year) { | ||
return year % 400 == 0 || year % 100 != 0 && year % 4 == 0; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
src/test/resources/analyzer/exercises/leap/UsingJavaTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import java.time.Year; | ||
|
||
class Leap { | ||
boolean isLeapYear(int year) { | ||
return Year.isLeap(year); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
tests/leap/using-gregorian-calendar/expected_analysis.json
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.