Repository navigation
Test generator #3186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Test generator #3186
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3c09127
simple-cipher: fix key length matching in decode in reference solution
jagdish-15 3732f20
feat: add automated JUnit 5 test generator tool and CLI script
jagdish-15 2c83537
hangman: configure tests.toml for RxJava FRP implementation
jagdish-15 c05df2a
Add custom templates and test generator support for practice exercises
jagdish-15 d5756a1
clock: consolidate tests into single ClockTest.java
jagdish-15 a7d68f0
test-generator: fix list-ops nested list indentation and foldLeft lambda
jagdish-15 c66af5b
Update test-generator README with CLI usage and template documentation
jagdish-15 54f2412
test-generator: throw IllegalArgumentException on null, blank, or non…
jagdish-15 7478812
Add execute permissions
jagdish-15 0b6e81d
Revert simple cipher reference solution
jagdish-15 7559668
Merge branch 'main' into test-generator
jagdish-15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,22 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
|
|
||
| # Default to --help if no arguments provided | ||
| if [ $# -eq 0 ]; then | ||
| ARGS="--help" | ||
| else | ||
| ARGS="$*" | ||
| fi | ||
|
|
||
| INSTALLED_APP="$REPO_ROOT/test-generator/build/install/test-generator/bin/test-generator" | ||
|
|
||
| # If not installed yet, build the distribution once | ||
| if [ ! -f "$INSTALLED_APP" ]; then | ||
| "$REPO_ROOT/test-generator/gradlew" -p "$REPO_ROOT/test-generator" installDist --quiet | ||
| fi | ||
|
|
||
| # Run pre-compiled binary directly (instant startup, zero Gradle daemon overhead!) | ||
| "$INSTALLED_APP" $ARGS |
This file contains hidden or 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,20 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class {{testClassName}} { | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| @DisplayName("{{{description}}}") | ||
| public void {{methodName}}() { | ||
| assertThat(new Acronym({{{formattedInputs.phrase}}}).get()) | ||
| .isEqualTo({{{expectedValue}}}); | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,31 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
|
||
| public class AffineCipherTest { | ||
|
|
||
| private AffineCipher affineCipher = new AffineCipher(); | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled}} | ||
| @Disabled("Remove to run test") | ||
| {{/if}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| {{#if expectedError}} | ||
| assertThatExceptionOfType(IllegalArgumentException.class) | ||
| .isThrownBy(() -> affineCipher.{{rawCase.property}}( | ||
| "{{{escapeJava rawCase.input.phrase}}}", {{rawCase.input.key.a}}, {{rawCase.input.key.b}})) | ||
| .withMessage("Error: keyA and alphabet size must be coprime."); | ||
| {{else}} | ||
| assertThat(affineCipher.{{rawCase.property}}( | ||
| "{{{escapeJava rawCase.input.phrase}}}", {{rawCase.input.key.a}}, {{rawCase.input.key.b}})) | ||
| .isEqualTo({{{expectedValue}}}); | ||
| {{/if}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,29 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
|
||
| public class BaseConverterTest { | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled}} | ||
| @Disabled("Remove to run test") | ||
| {{/if}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| {{#if expectedError}} | ||
| assertThatExceptionOfType(IllegalArgumentException.class) | ||
| .isThrownBy(() -> new BaseConverter({{{formattedInputs.inputBase}}}, {{{asIntArray rawCase.input.digits}}}) | ||
| .convertToBase({{{formattedInputs.outputBase}}})) | ||
| .withMessage("{{{allYourBaseErrorMessage this}}}"); | ||
| {{else}} | ||
| assertThat(new BaseConverter({{{formattedInputs.inputBase}}}, {{{asIntArray rawCase.input.digits}}}) | ||
| .convertToBase({{{formattedInputs.outputBase}}})) | ||
| .containsExactly({{{formatElements rawCase.expected}}}); | ||
| {{/if}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,30 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class AllergiesTest { | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| {{#if (eq property "allergicTo")~}} | ||
| assertThat(new Allergies({{{formattedInputs.score}}}).isAllergicTo({{toAllergen inputNodes.item}})) | ||
| .{{#if (eq expectedValue "true")}}isTrue(){{else}}isFalse(){{/if}}; | ||
| {{~else~}} | ||
| {{#if (eq rawCase.expected.size 0)~}} | ||
| assertThat(new Allergies({{{formattedInputs.score}}}).getList()) | ||
| .isEmpty(); | ||
| {{~else~}} | ||
| assertThat(new Allergies({{{formattedInputs.score}}}).getList()) | ||
| .containsExactly({{{asAllergens rawCase.expected}}}); | ||
| {{~/if}} | ||
| {{~/if}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,29 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static java.util.Map.entry; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
|
||
| public class AlphameticsTest { | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled}} | ||
| @Disabled("Remove to run test") | ||
| {{/if}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() throws UnsolvablePuzzleException { | ||
| {{#if isNullExpected}} | ||
| assertThatExceptionOfType(UnsolvablePuzzleException.class) | ||
| .isThrownBy(() -> new Alphametics({{{alphameticsPuzzle rawCase.input.puzzle}}}).solve()); | ||
| {{else}} | ||
| assertThat(new Alphametics({{{alphameticsPuzzle rawCase.input.puzzle}}}).solve()) | ||
| .isEqualTo({{{formatAlphameticsExpected rawCase.expected}}}); | ||
| {{/if}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,22 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class AnagramTest { | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| assertThat(new Anagram({{{formattedInputs.subject}}}).match({{{formattedInputs.candidates}}})) | ||
| .containsExactlyInAnyOrderElementsOf({{{expectedValue}}}); | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,53 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.offset; | ||
|
|
||
| public class BafflingBirthdaysTest { | ||
|
|
||
| private BafflingBirthdays birthdays = new BafflingBirthdays(); | ||
|
|
||
| {{#each testCases}} | ||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| {{#if (eq rawCase.property "sharedBirthday")}} | ||
| List<LocalDate> birthdates = {{{asLocalDateList rawCase.input.birthdates}}}; | ||
| {{#if (eq rawCase.expected true)}} | ||
| assertThat(birthdays.sharedBirthday(birthdates)).isTrue(); | ||
| {{else}} | ||
| assertThat(birthdays.sharedBirthday(birthdates)).isFalse(); | ||
| {{/if}} | ||
| {{else if (eq rawCase.property "randomBirthdates")}} | ||
| {{#if rawCase.expected.years}} | ||
| assertThat(birthdays.randomBirthdates(100)).noneMatch(LocalDate::isLeapYear); | ||
| {{else if rawCase.expected.months}} | ||
| assertThat(birthdays.randomBirthdates(500).stream().map(LocalDate::getMonth).distinct()) | ||
| .hasSizeGreaterThanOrEqualTo(7); | ||
| {{else if rawCase.expected.days}} | ||
| assertThat(birthdays.randomBirthdates(500).stream().map(LocalDate::getDayOfMonth).distinct()) | ||
| .hasSizeGreaterThanOrEqualTo(11); | ||
| {{else}} | ||
| int groupSize = 50; | ||
| assertThat(birthdays.randomBirthdates(groupSize).size()).isEqualTo(groupSize); | ||
| {{/if}} | ||
| {{else if (eq rawCase.property "estimatedProbabilityOfSharedBirthday")}} | ||
| {{#if (eq rawCase.expected 0.0)}} | ||
| assertThat(birthdays.estimatedProbabilityOfSharedBirthday({{rawCase.input.groupSize}})) | ||
| .isEqualTo(0.0); | ||
| {{else}} | ||
| assertThat(birthdays.estimatedProbabilityOfSharedBirthday({{rawCase.input.groupSize}})) | ||
| .isCloseTo({{rawCase.expected}}, offset(1.0)); | ||
| {{/if}} | ||
| {{/if}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,23 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
| import static org.assertj.core.api.Assertions.fail; | ||
|
|
||
| public class BankAccountTest { | ||
|
|
||
| {{#each testCases}} | ||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() throws Exception { | ||
| {{{renderBankAccountCase rawCase}}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,21 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class BinarySearchTreeTest { | ||
|
|
||
| {{#each testCases}} | ||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| {{{renderBinarySearchTreeCase rawCase}}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,31 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
|
||
| public class BinarySearchTest { | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled}} | ||
| @Disabled("Remove to run test") | ||
| {{/if}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() throws ValueNotFoundException { | ||
| {{#if expectedError}} | ||
| assertThatExceptionOfType(ValueNotFoundException.class) | ||
| .isThrownBy(() -> new BinarySearch({{{formattedInputs.array}}}) | ||
| .indexOf({{{formattedInputs.value}}})) | ||
| .withMessage("Value not in array"); | ||
| {{else}} | ||
| assertThat(new BinarySearch({{{formattedInputs.array}}}) | ||
| .indexOf({{{formattedInputs.value}}})) | ||
| .isEqualTo({{{expectedValue}}}); | ||
| {{/if}} | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,20 @@ | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class BobTest { | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| assertThat(new Bob().hey({{{formattedInputs.heyBob}}})) | ||
| .isEqualTo({{{expectedValue}}}); | ||
| } | ||
| {{/each}} | ||
| } |
This file contains hidden or 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,33 @@ | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.offset; | ||
|
|
||
| public class {{testClassName}} { | ||
|
|
||
| // A 0.01 tolerance covers minor rounding variations in floating point calculations | ||
| private static final double EQUALITY_TOLERANCE = 0.01; | ||
|
|
||
| private BookStore bookStore; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| bookStore = new BookStore(); | ||
| } | ||
| {{#each testCases}} | ||
|
|
||
| {{#if disabled~}} | ||
| @Disabled("Remove to run test") | ||
| {{/if~}} | ||
| @Test | ||
| {{{displayNameAnnotation}}} | ||
| public void {{methodName}}() { | ||
| {{{renderBookStoreCase this}}} | ||
| } | ||
| {{/each}} | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.