diff --git a/config.json b/config.json index e13b0d2..aeb7acc 100644 --- a/config.json +++ b/config.json @@ -242,6 +242,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "bottle-song", + "name": "Bottle Song", + "uuid": "b1d58dbf-127f-4997-a1d8-09d0c5a16c8f", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "clock", "name": "Clock", diff --git a/docs/ABOUT.md b/docs/ABOUT.md index 1da5730..260cbc8 100644 --- a/docs/ABOUT.md +++ b/docs/ABOUT.md @@ -21,4 +21,4 @@ For those familiar with Lua, the transition is often smooth, as MoonScript's syn [lua]: https://exercism.org/tracks/lua/about [moon]: https://moonscript.org [github]: https://github.com/leafo/moonscript -[discord]: https://discord.gg/invite/Y75ZXrD +[discord]: https://discord.com/invite/Y75ZXrD diff --git a/exercises/practice/bottle-song/.busted b/exercises/practice/bottle-song/.busted new file mode 100644 index 0000000..86b84e7 --- /dev/null +++ b/exercises/practice/bottle-song/.busted @@ -0,0 +1,5 @@ +return { + default = { + ROOT = { '.' } + } +} diff --git a/exercises/practice/bottle-song/.docs/instructions.md b/exercises/practice/bottle-song/.docs/instructions.md new file mode 100644 index 0000000..febdfc8 --- /dev/null +++ b/exercises/practice/bottle-song/.docs/instructions.md @@ -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. +``` diff --git a/exercises/practice/bottle-song/.meta/config.json b/exercises/practice/bottle-song/.meta/config.json new file mode 100644 index 0000000..99b7abc --- /dev/null +++ b/exercises/practice/bottle-song/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "glennj" + ], + "files": { + "solution": [ + "bottle_song.moon" + ], + "test": [ + "bottle_song_spec.moon" + ], + "example": [ + ".meta/example.moon" + ] + }, + "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" +} diff --git a/exercises/practice/bottle-song/.meta/example.moon b/exercises/practice/bottle-song/.meta/example.moon new file mode 100644 index 0000000..7e58507 --- /dev/null +++ b/exercises/practice/bottle-song/.meta/example.moon @@ -0,0 +1,17 @@ +nums = {[0]: "No", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"} + +bottles = (n) -> "#{nums[n]} green bottle#{n == 1 and "" or "s"}" + +verse = (v) -> + lines = { + "#{bottles v} hanging on the wall," + "And if one green bottle should accidentally fall," + "There'll be #{string.lower bottles v - 1} hanging on the wall." + } + table.insert lines, 1, lines[1] + table.concat lines, '\n' + +{ + recite: (first, count) -> + table.concat [verse(v) for v = first, first - count + 1, -1], '\n\n' +} diff --git a/exercises/practice/bottle-song/.meta/generator.tmpl b/exercises/practice/bottle-song/.meta/generator.tmpl new file mode 100644 index 0000000..711a7f8 --- /dev/null +++ b/exercises/practice/bottle-song/.meta/generator.tmpl @@ -0,0 +1,18 @@ +import recite from require <%- h.quote(slug.snake) %> + +describe <%- h.quote(slug.kebab .. ':') %>, -> +<% for i, g1 in ipairs(data.cases) do -%> +<% for j, g2 in ipairs(g1.cases) do -%> + describe <%- h.quote(g2.description) %>, -> +<% for k, case in ipairs(g2.cases) do -%> + <%= test_cmd(i == 1 and j == 1 and k == 1) %> <%- h.quote(case.description) %>, -> +<% if not case.expected.error then -%> + expected = [[ +<%- table.concat(case.expected, '\n') %>]] + result = <%= case.property %> <%= case.input.startBottles %>, <%= case.input.takeDown %> + assert.are.same expected, result +<% end -%> + +<% end -%> +<% end -%> +<% end -%> diff --git a/exercises/practice/bottle-song/.meta/tests.toml b/exercises/practice/bottle-song/.meta/tests.toml new file mode 100644 index 0000000..1f6e40a --- /dev/null +++ b/exercises/practice/bottle-song/.meta/tests.toml @@ -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" diff --git a/exercises/practice/bottle-song/bottle_song.moon b/exercises/practice/bottle-song/bottle_song.moon new file mode 100644 index 0000000..b1991c9 --- /dev/null +++ b/exercises/practice/bottle-song/bottle_song.moon @@ -0,0 +1,4 @@ +{ + recite: (startVerse, numToTake) -> + error 'Implement me' +} diff --git a/exercises/practice/bottle-song/bottle_song_spec.moon b/exercises/practice/bottle-song/bottle_song_spec.moon new file mode 100644 index 0000000..9c725e7 --- /dev/null +++ b/exercises/practice/bottle-song/bottle_song_spec.moon @@ -0,0 +1,128 @@ +import recite from require 'bottle_song' + +describe 'bottle-song:', -> + describe 'single verse', -> + it 'first generic verse', -> + expected = [[ +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.]] + result = recite 10, 1 + assert.are.same expected, result + + pending 'last generic verse', -> + expected = [[ +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.]] + result = recite 3, 1 + assert.are.same expected, result + + pending 'verse with 2 bottles', -> + expected = [[ +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.]] + result = recite 2, 1 + assert.are.same expected, result + + pending 'verse with 1 bottle', -> + expected = [[ +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.]] + result = recite 1, 1 + assert.are.same expected, result + + describe 'multiple verses', -> + pending 'first two verses', -> + expected = [[ +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.]] + result = recite 10, 2 + assert.are.same expected, result + + pending 'last three verses', -> + expected = [[ +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.]] + result = recite 3, 3 + assert.are.same expected, result + + pending 'all verses', -> + expected = [[ +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.]] + result = recite 10, 10 + assert.are.same expected, result +