-
-
Notifications
You must be signed in to change notification settings - Fork 131
Bottle song #857
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
Bottle song #857
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4be4803
Add script to scaffold practice exercises
d51ebea
Add "Bottle Song" exercise to config.json
b0172be
Add build.sbt for Bottle Song practice exercise
b445ca5
Add tests for BottleSong recitation functionality
d6eed1f
Add BottleSong exercise with implementation and tests
8054050
Add instructions for the "bottle song" practice exercise
6ff71fc
Add metadata config for 'Bottle Song' practice exercise
56177cc
Add example implementation for Bottle Song practice exercise
6c980e4
Add sbt build properties file for bottle-song project
539cdaf
Mark BottleSongTest cases as pending.
95e8e55
Remove unused topics attribute from config.json
56204dd
Remove unused add-practice-exercise script
e5bb824
Update CI workflow to use Ubuntu 22.04
cd00c9c
Add recite method skeleton to BottleSong
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Synopsis: | ||
# Scaffold the files for a new practice exercise. | ||
# After creating the exercise, follow the instructions in the output. | ||
|
||
# Example: | ||
# bin/add-practice-exercise two-fer | ||
|
||
# Example with difficulty: | ||
# bin/add-practice-exercise -d 5 two-fer | ||
|
||
# Example with author and difficulty: | ||
# bin/add-practice-exercise -a foo -d 3 two-fer | ||
|
||
set -euo pipefail | ||
scriptname=$0 | ||
|
||
help_and_exit() { | ||
echo >&2 "Scaffold the files for a new practice exercise." | ||
echo >&2 "Usage: ${scriptname} [-h] [-a author] [-d difficulty] <exercise-slug>" | ||
echo >&2 "Where: author is the GitHub username of the exercise creator." | ||
echo >&2 "Where: difficulty is between 1 (easiest) to 10 (hardest)." | ||
exit 1 | ||
} | ||
|
||
die() { echo >&2 "$*"; exit 1; } | ||
|
||
required_tool() { | ||
command -v "${1}" >/dev/null 2>&1 || | ||
die "${1} is required but not installed. Please install it and make sure it's in your PATH." | ||
} | ||
|
||
require_files_template() { | ||
jq -e --arg key "${1}" '.files[$key] | length > 0' config.json > /dev/null || | ||
die "The '.files.${1}' array in the 'config.json' file is empty. Please add at least one file. See https://exercism.org/docs/building/tracks/config-json#h-files for more information." | ||
} | ||
|
||
required_tool jq | ||
|
||
require_files_template "solution" | ||
require_files_template "test" | ||
require_files_template "example" | ||
|
||
[[ -f ./bin/fetch-configlet ]] || die "Run this script from the repo's root directory." | ||
|
||
author='' | ||
difficulty='1' | ||
while getopts :ha:d: opt; do | ||
case $opt in | ||
h) help_and_exit ;; | ||
a) author=$OPTARG ;; | ||
d) difficulty=$OPTARG ;; | ||
?) echo >&2 "Unknown option: -$OPTARG"; help_and_exit ;; | ||
esac | ||
done | ||
shift "$((OPTIND - 1))" | ||
|
||
(( $# >= 1 )) || help_and_exit | ||
|
||
slug="${1}" | ||
|
||
if [[ -z "${author}" ]]; then | ||
read -rp 'Your GitHub username: ' author | ||
fi | ||
|
||
./bin/fetch-configlet | ||
./bin/configlet create --practice-exercise "${slug}" --author "${author}" --difficulty "${difficulty}" | ||
|
||
exercise_dir="exercises/practice/${slug}" | ||
files=$(jq -r --arg dir "${exercise_dir}" '.files | to_entries | map({key: .key, value: (.value | map("'"'"'" + $dir + "/" + . + "'"'"'") | join(" and "))}) | from_entries' "${exercise_dir}/.meta/config.json") | ||
|
||
cat << NEXT_STEPS | ||
|
||
Your next steps are: | ||
- Create the test suite in $(jq -r '.test' <<< "${files}") | ||
- The tests should be based on the canonical data at 'https://github.com/exercism/problem-specifications/blob/main/exercises/${slug}/canonical-data.json' | ||
- Any test cases you don't implement, mark them in 'exercises/practice/${slug}/.meta/tests.toml' with "include = false" | ||
- Create the example solution in $(jq -r '.example' <<< "${files}") | ||
- Verify the example solution passes the tests by running 'bin/verify-exercises ${slug}' | ||
- Create the stub solution in $(jq -r '.solution' <<< "${files}") | ||
- Update the 'difficulty' value for the exercise's entry in the 'config.json' file in the repo's root | ||
- Validate CI using 'bin/configlet lint' and 'bin/configlet fmt' | ||
NEXT_STEPS |
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,57 @@ | ||
# Instructions | ||
|
||
Recite the lyrics to that popular children's repetitive song: Ten Green Bottles. | ||
|
||
Note that not all verses are identical. | ||
|
||
```text | ||
Ten green bottles hanging on the wall, | ||
Ten green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be nine green bottles hanging on the wall. | ||
|
||
Nine green bottles hanging on the wall, | ||
Nine green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be eight green bottles hanging on the wall. | ||
|
||
Eight green bottles hanging on the wall, | ||
Eight green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be seven green bottles hanging on the wall. | ||
|
||
Seven green bottles hanging on the wall, | ||
Seven green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be six green bottles hanging on the wall. | ||
|
||
Six green bottles hanging on the wall, | ||
Six green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be five green bottles hanging on the wall. | ||
|
||
Five green bottles hanging on the wall, | ||
Five green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be four green bottles hanging on the wall. | ||
|
||
Four green bottles hanging on the wall, | ||
Four green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be three green bottles hanging on the wall. | ||
|
||
Three green bottles hanging on the wall, | ||
Three green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be two green bottles hanging on the wall. | ||
|
||
Two green bottles hanging on the wall, | ||
Two green bottles hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be one green bottle hanging on the wall. | ||
|
||
One green bottle hanging on the wall, | ||
One green bottle hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be no green bottles hanging on the wall. | ||
``` |
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,17 @@ | ||
object BottleSong: | ||
private val numbers = List("no", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten") | ||
|
||
private def suffix(bottles: Int) = if bottles == 1 then "" else "s" | ||
|
||
private def hanging(bottles: Int) = | ||
s"${numbers(bottles)} green bottle${suffix(bottles)} hanging on the wall" | ||
|
||
private def firstLine(bottles: Int) = hanging(bottles) + ",\n" | ||
|
||
private def lastLine(bottles: Int) = "There'll be " + hanging(bottles).toLowerCase + ".\n" | ||
|
||
private def verse(bottles: Int) = firstLine(bottles).repeat(2) + | ||
"And if one green bottle should accidentally fall,\n" + lastLine(bottles - 1) | ||
|
||
def recite(startBottles: Int, takeDown: Int): String = | ||
startBottles until startBottles - takeDown by -1 map verse mkString "\n" |
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,19 @@ | ||
{ | ||
"authors": [ | ||
"rabestro" | ||
], | ||
"files": { | ||
"solution": [ | ||
"src/main/scala/BottleSong.scala" | ||
], | ||
"test": [ | ||
"src/test/scala/BottleSongTest.scala" | ||
], | ||
"example": [ | ||
".meta/Example.scala" | ||
] | ||
}, | ||
"blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.", | ||
"source": "Wikipedia", | ||
"source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles" | ||
} |
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 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[d4ccf8fc-01dc-48c0-a201-4fbeb30f2d03] | ||
description = "verse -> single verse -> first generic verse" | ||
|
||
[0f0aded3-472a-4c64-b842-18d4f1f5f030] | ||
description = "verse -> single verse -> last generic verse" | ||
|
||
[f61f3c97-131f-459e-b40a-7428f3ed99d9] | ||
description = "verse -> single verse -> verse with 2 bottles" | ||
|
||
[05eadba9-5dbd-401e-a7e8-d17cc9baa8e0] | ||
description = "verse -> single verse -> verse with 1 bottle" | ||
|
||
[a4a28170-83d6-4dc1-bd8b-319b6abb6a80] | ||
description = "lyrics -> multiple verses -> first two verses" | ||
|
||
[3185d438-c5ac-4ce6-bcd3-02c9ff1ed8db] | ||
description = "lyrics -> multiple verses -> last three verses" | ||
|
||
[28c1584a-0e51-4b65-9ae2-fbc0bf4bbb28] | ||
description = "lyrics -> multiple verses -> all verses" |
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,3 @@ | ||
scalaVersion := "3.4.2" | ||
|
||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % Test |
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 @@ | ||
sbt.version=1.10.1 |
rabestro marked this conversation as resolved.
Show resolved
Hide resolved
|
Empty file.
134 changes: 134 additions & 0 deletions
134
exercises/practice/bottle-song/src/test/scala/BottleSongTest.scala
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,134 @@ | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class BottleSongTest extends AnyFunSuite with Matchers { | ||
|
||
test("first generic verse") { | ||
BottleSong.recite(10, 1) shouldBe | ||
"""Ten green bottles hanging on the wall, | ||
|Ten green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be nine green bottles hanging on the wall. | ||
|""".stripMargin.trim + "\n" | ||
} | ||
|
||
test("last generic verse") { | ||
pending | ||
BottleSong.recite(3, 1) shouldBe | ||
"""Three green bottles hanging on the wall, | ||
|Three green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be two green bottles hanging on the wall. | ||
|""".stripMargin.trim + "\n" | ||
} | ||
|
||
test("verse with two bottles") { | ||
pending | ||
BottleSong.recite(2, 1) shouldBe | ||
"""Two green bottles hanging on the wall, | ||
|Two green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be one green bottle hanging on the wall. | ||
|""".stripMargin.trim + "\n" | ||
} | ||
|
||
test("verse with one bottle") { | ||
pending | ||
BottleSong.recite(1, 1) shouldBe | ||
"""One green bottle hanging on the wall, | ||
|One green bottle hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be no green bottles hanging on the wall. | ||
|""".stripMargin.trim + "\n" | ||
} | ||
|
||
test("first two verses") { | ||
pending | ||
BottleSong.recite(10, 2) shouldBe | ||
"""Ten green bottles hanging on the wall, | ||
|Ten green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be nine green bottles hanging on the wall. | ||
| | ||
|Nine green bottles hanging on the wall, | ||
|Nine green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be eight green bottles hanging on the wall. | ||
|""".stripMargin.trim + "\n" | ||
} | ||
|
||
test("last three verses") { | ||
pending | ||
BottleSong.recite(3, 3) shouldBe | ||
"""Three green bottles hanging on the wall, | ||
|Three green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be two green bottles hanging on the wall. | ||
| | ||
|Two green bottles hanging on the wall, | ||
|Two green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be one green bottle hanging on the wall. | ||
| | ||
|One green bottle hanging on the wall, | ||
|One green bottle hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be no green bottles hanging on the wall. | ||
|""".stripMargin.trim + "\n" | ||
} | ||
|
||
test("all verses") { | ||
pending | ||
BottleSong.recite(10, 10) shouldBe | ||
"""Ten green bottles hanging on the wall, | ||
|Ten green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be nine green bottles hanging on the wall. | ||
| | ||
|Nine green bottles hanging on the wall, | ||
|Nine green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be eight green bottles hanging on the wall. | ||
| | ||
|Eight green bottles hanging on the wall, | ||
|Eight green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be seven green bottles hanging on the wall. | ||
| | ||
|Seven green bottles hanging on the wall, | ||
|Seven green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be six green bottles hanging on the wall. | ||
| | ||
|Six green bottles hanging on the wall, | ||
|Six green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be five green bottles hanging on the wall. | ||
| | ||
|Five green bottles hanging on the wall, | ||
|Five green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be four green bottles hanging on the wall. | ||
| | ||
|Four green bottles hanging on the wall, | ||
|Four green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be three green bottles hanging on the wall. | ||
| | ||
|Three green bottles hanging on the wall, | ||
|Three green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be two green bottles hanging on the wall. | ||
| | ||
|Two green bottles hanging on the wall, | ||
|Two green bottles hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be one green bottle hanging on the wall. | ||
| | ||
|One green bottle hanging on the wall, | ||
|One green bottle hanging on the wall, | ||
|And if one green bottle should accidentally fall, | ||
|There'll be no green bottles hanging on the wall. | ||
|""".stripMargin.trim + "\n" | ||
} | ||
} |
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.