From 31b6d31970d404ec08e53520c2ee2abfd9b43420 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 8 May 2023 15:13:23 -0300 Subject: [PATCH] Starting with Groovy --- .editorconfig | 6 +++ .gitignore | 6 +++ groovy/hello-world/.exercism/config.json | 25 ++++++++++ groovy/hello-world/.exercism/metadata.json | 1 + groovy/hello-world/HELP.md | 48 +++++++++++++++++++ groovy/hello-world/README.md | 38 +++++++++++++++ groovy/hello-world/build.gradle | 18 +++++++ .../src/main/groovy/HelloWorld.groovy | 7 +++ .../src/test/groovy/HelloWorldSpec.groovy | 13 +++++ groovy/two-fer/.exercism/config.json | 23 +++++++++ groovy/two-fer/.exercism/metadata.json | 1 + groovy/two-fer/HELP.md | 48 +++++++++++++++++++ groovy/two-fer/README.md | 48 +++++++++++++++++++ groovy/two-fer/build.gradle | 18 +++++++ groovy/two-fer/src/main/groovy/TwoFer.groovy | 9 ++++ .../two-fer/src/test/groovy/TwoFerSpec.groovy | 36 ++++++++++++++ 16 files changed, 345 insertions(+) create mode 100644 .editorconfig create mode 100644 groovy/hello-world/.exercism/config.json create mode 100644 groovy/hello-world/.exercism/metadata.json create mode 100644 groovy/hello-world/HELP.md create mode 100644 groovy/hello-world/README.md create mode 100644 groovy/hello-world/build.gradle create mode 100644 groovy/hello-world/src/main/groovy/HelloWorld.groovy create mode 100644 groovy/hello-world/src/test/groovy/HelloWorldSpec.groovy create mode 100644 groovy/two-fer/.exercism/config.json create mode 100644 groovy/two-fer/.exercism/metadata.json create mode 100644 groovy/two-fer/HELP.md create mode 100644 groovy/two-fer/README.md create mode 100644 groovy/two-fer/build.gradle create mode 100644 groovy/two-fer/src/main/groovy/TwoFer.groovy create mode 100644 groovy/two-fer/src/test/groovy/TwoFerSpec.groovy diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..03b01f8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.groovy] +indent_style = space +indent_size = 4 + diff --git a/.gitignore b/.gitignore index e02906b..b496fe9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,9 @@ _build # TypeScript/JavaScript **/node_modules/** + +# Groovy +**/build/** +**/gradle* +**/.gradle/** +**/gradle/** diff --git a/groovy/hello-world/.exercism/config.json b/groovy/hello-world/.exercism/config.json new file mode 100644 index 0000000..f6f2beb --- /dev/null +++ b/groovy/hello-world/.exercism/config.json @@ -0,0 +1,25 @@ +{ + "authors": [ + "duffn" + ], + "contributors": [ + "alexanderific", + "amscotti", + "Dispader", + "kytrinyx" + ], + "files": { + "solution": [ + "src/main/groovy/HelloWorld.groovy" + ], + "test": [ + "src/test/groovy/HelloWorldSpec.groovy" + ], + "example": [ + ".meta/src/reference/groovy/HelloWorld.groovy" + ] + }, + "blurb": "The classical introductory exercise. Just say \"Hello, World!\".", + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/groovy/hello-world/.exercism/metadata.json b/groovy/hello-world/.exercism/metadata.json new file mode 100644 index 0000000..3874fbe --- /dev/null +++ b/groovy/hello-world/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"groovy","exercise":"hello-world","id":"019a349fbd6141aa90ccecb1ae98683e","url":"https://exercism.org/tracks/groovy/exercises/hello-world","handle":"JBiason","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/groovy/hello-world/HELP.md b/groovy/hello-world/HELP.md new file mode 100644 index 0000000..6b95893 --- /dev/null +++ b/groovy/hello-world/HELP.md @@ -0,0 +1,48 @@ +# Help + +## Running the tests + +On MacOS/Linux, please run: + +```sh +$ chmod +x gradlew +``` + +Execute the tests with: + +```sh +$ ./gradlew test +``` + +> Use `gradlew.bat` if you're on Windows + +## Skipped tests + +After the first test(s) pass, continue by commenting out or removing the `@Ignore` annotations prepending other tests. + +## Submitting your solution + +You can submit your solution using the `exercism submit src/main/groovy/HelloWorld.groovy` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Groovy track's documentation](https://exercism.org/docs/tracks/groovy) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- The [Groovy Language Documentation](http://docs.groovy-lang.org/docs/latest/html/documentation/) +- The [Groovy Community](http://www.groovy-lang.org/community.html) entry of the Groovy Language Documentation +- [/r/groovy](https://www.reddit.com/r/groovy) is the Groovy subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/groovy) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/groovy/hello-world/README.md b/groovy/hello-world/README.md new file mode 100644 index 0000000..6fa2f0b --- /dev/null +++ b/groovy/hello-world/README.md @@ -0,0 +1,38 @@ +# Hello World + +Welcome to Hello World on Exercism's Groovy Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +The classical introductory exercise. +Just say "Hello, World!". + +["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment. + +The objectives are simple: + +- Modify the provided code so that it produces the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +## Source + +### Created by + +- @duffn + +### Contributed to by + +- @alexanderific +- @amscotti +- @Dispader +- @kytrinyx + +### Based on + +This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file diff --git a/groovy/hello-world/build.gradle b/groovy/hello-world/build.gradle new file mode 100644 index 0000000..e16cd99 --- /dev/null +++ b/groovy/hello-world/build.gradle @@ -0,0 +1,18 @@ +apply plugin: "groovy" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation "org.spockframework:spock-core:2.0-M2-groovy-3.0" + implementation "org.codehaus.groovy:groovy-all:3.0.2" +} + +test { + useJUnitPlatform() + testLogging { + exceptionFormat = 'full' + events = ["passed", "failed", "skipped"] + } +} \ No newline at end of file diff --git a/groovy/hello-world/src/main/groovy/HelloWorld.groovy b/groovy/hello-world/src/main/groovy/HelloWorld.groovy new file mode 100644 index 0000000..991de5f --- /dev/null +++ b/groovy/hello-world/src/main/groovy/HelloWorld.groovy @@ -0,0 +1,7 @@ +class HelloWorld { + + def hello() { + 'Hello, World!' + } + +} diff --git a/groovy/hello-world/src/test/groovy/HelloWorldSpec.groovy b/groovy/hello-world/src/test/groovy/HelloWorldSpec.groovy new file mode 100644 index 0000000..eb22795 --- /dev/null +++ b/groovy/hello-world/src/test/groovy/HelloWorldSpec.groovy @@ -0,0 +1,13 @@ +import spock.lang.* + +class HelloWorldSpec extends Specification { + + def "Say Hi!"() { + expect: + new HelloWorld().hello() == expected + + where: + expected = 'Hello, World!' + } + +} diff --git a/groovy/two-fer/.exercism/config.json b/groovy/two-fer/.exercism/config.json new file mode 100644 index 0000000..3eca2c5 --- /dev/null +++ b/groovy/two-fer/.exercism/config.json @@ -0,0 +1,23 @@ +{ + "authors": [ + "ikhadykin" + ], + "contributors": [ + "amscotti", + "mattmoss", + "sjwarner-bp" + ], + "files": { + "solution": [ + "src/main/groovy/TwoFer.groovy" + ], + "test": [ + "src/test/groovy/TwoFerSpec.groovy" + ], + "example": [ + ".meta/src/reference/groovy/TwoFer.groovy" + ] + }, + "blurb": "Create a sentence of the form \"One for X, one for me.\".", + "source_url": "https://github.com/exercism/problem-specifications/issues/757" +} diff --git a/groovy/two-fer/.exercism/metadata.json b/groovy/two-fer/.exercism/metadata.json new file mode 100644 index 0000000..0df0b49 --- /dev/null +++ b/groovy/two-fer/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"groovy","exercise":"two-fer","id":"1146ca2f98784150b4277877b3e13927","url":"https://exercism.org/tracks/groovy/exercises/two-fer","handle":"JBiason","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/groovy/two-fer/HELP.md b/groovy/two-fer/HELP.md new file mode 100644 index 0000000..d930b41 --- /dev/null +++ b/groovy/two-fer/HELP.md @@ -0,0 +1,48 @@ +# Help + +## Running the tests + +On MacOS/Linux, please run: + +```sh +$ chmod +x gradlew +``` + +Execute the tests with: + +```sh +$ ./gradlew test +``` + +> Use `gradlew.bat` if you're on Windows + +## Skipped tests + +After the first test(s) pass, continue by commenting out or removing the `@Ignore` annotations prepending other tests. + +## Submitting your solution + +You can submit your solution using the `exercism submit src/main/groovy/TwoFer.groovy` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Groovy track's documentation](https://exercism.org/docs/tracks/groovy) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- The [Groovy Language Documentation](http://docs.groovy-lang.org/docs/latest/html/documentation/) +- The [Groovy Community](http://www.groovy-lang.org/community.html) entry of the Groovy Language Documentation +- [/r/groovy](https://www.reddit.com/r/groovy) is the Groovy subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/groovy) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/groovy/two-fer/README.md b/groovy/two-fer/README.md new file mode 100644 index 0000000..42bc3de --- /dev/null +++ b/groovy/two-fer/README.md @@ -0,0 +1,48 @@ +# Two Fer + +Welcome to Two Fer on Exercism's Groovy Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +`Two-fer` or `2-fer` is short for two for one. +One for you and one for me. + +Given a name, return a string with the message: + +```text +One for name, one for me. +``` + +Where "name" is the given name. + +However, if the name is missing, return the string: + +```text +One for you, one for me. +``` + +Here are some examples: + +|Name |String to return +|:-------|:------------------ +|Alice |One for Alice, one for me. +|Bob |One for Bob, one for me. +| |One for you, one for me. +|Zaphod |One for Zaphod, one for me. + +## Source + +### Created by + +- @ikhadykin + +### Contributed to by + +- @amscotti +- @mattmoss +- @sjwarner-bp + +### Based on + +https://github.com/exercism/problem-specifications/issues/757 \ No newline at end of file diff --git a/groovy/two-fer/build.gradle b/groovy/two-fer/build.gradle new file mode 100644 index 0000000..e16cd99 --- /dev/null +++ b/groovy/two-fer/build.gradle @@ -0,0 +1,18 @@ +apply plugin: "groovy" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation "org.spockframework:spock-core:2.0-M2-groovy-3.0" + implementation "org.codehaus.groovy:groovy-all:3.0.2" +} + +test { + useJUnitPlatform() + testLogging { + exceptionFormat = 'full' + events = ["passed", "failed", "skipped"] + } +} \ No newline at end of file diff --git a/groovy/two-fer/src/main/groovy/TwoFer.groovy b/groovy/two-fer/src/main/groovy/TwoFer.groovy new file mode 100644 index 0000000..04ea2b1 --- /dev/null +++ b/groovy/two-fer/src/main/groovy/TwoFer.groovy @@ -0,0 +1,9 @@ +class TwoFer { + + static String twoFer(String name) { + if (!name) { + name = 'you' + } + "One for ${name}, one for me." + } +} diff --git a/groovy/two-fer/src/test/groovy/TwoFerSpec.groovy b/groovy/two-fer/src/test/groovy/TwoFerSpec.groovy new file mode 100644 index 0000000..6902a78 --- /dev/null +++ b/groovy/two-fer/src/test/groovy/TwoFerSpec.groovy @@ -0,0 +1,36 @@ +import spock.lang.* + +class TwoFerSpec extends Specification { + + def "No name given"() { + expect: + TwoFer.twoFer() == 'One for you, one for me.' + } + + def "Empty name given"() { + expect: + TwoFer.twoFer(name) == expected + + where: + name || expected + '' || 'One for you, one for me.' + } + + def "A name given"() { + expect: + TwoFer.twoFer(name) == expected + + where: + name || expected + 'Alice' || 'One for Alice, one for me.' + } + + def "Another name given"() { + expect: + TwoFer.twoFer(name) == expected + + where: + name || expected + 'Bob' || 'One for Bob, one for me.' + } +}