Added bottle_song
This commit is contained in:
20
config.json
20
config.json
@@ -2151,6 +2151,26 @@
|
||||
"difficulty": 3,
|
||||
"status": "deprecated"
|
||||
},
|
||||
{
|
||||
"slug": "bottle-song",
|
||||
"name": "Bottle Song",
|
||||
"uuid": "70bec74a-0677-40c9-b9c9-cbcc49a2eae4",
|
||||
"practices": ["generators"],
|
||||
"prerequisites": [
|
||||
"basics",
|
||||
"conditionals",
|
||||
"dicts",
|
||||
"lists",
|
||||
"list-methods",
|
||||
"loops",
|
||||
"numbers",
|
||||
"strings",
|
||||
"string-methods",
|
||||
"tuples"
|
||||
],
|
||||
"difficulty": 3,
|
||||
"status": "deprecated"
|
||||
},
|
||||
{
|
||||
"slug": "trinary",
|
||||
"name": "Trinary",
|
||||
|
||||
57
exercises/practice/bottle-song/.docs/instructions.md
Normal file
57
exercises/practice/bottle-song/.docs/instructions.md
Normal file
@@ -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.
|
||||
```
|
||||
19
exercises/practice/bottle-song/.meta/config.json
Normal file
19
exercises/practice/bottle-song/.meta/config.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"blurb": "Produce the lyrics to the popular children's repetitive song: Ten Green Bottles.",
|
||||
"authors": ["meatball133", "BethanyG"],
|
||||
"contributors": [
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"bottle_song.py"
|
||||
],
|
||||
"test": [
|
||||
"bottle_song_test.py"
|
||||
],
|
||||
"example": [
|
||||
".meta/example.py"
|
||||
]
|
||||
},
|
||||
"source": "Wikipedia",
|
||||
"source_url": "https://en.wikipedia.org/wiki/Ten_Green_Bottles"
|
||||
}
|
||||
34
exercises/practice/bottle-song/.meta/example.py
Normal file
34
exercises/practice/bottle-song/.meta/example.py
Normal file
@@ -0,0 +1,34 @@
|
||||
NUMBERS = {10: "ten", 9: "nine", 8: "eight", 7: "seven", 6: "six", 5: "five", 4: "four", 3: "three", 2: "two", 1: "one", 0: "no"}
|
||||
|
||||
def recite(start, take=1):
|
||||
results = []
|
||||
for idx in range(start, start - take, -1):
|
||||
results.extend(verse(idx))
|
||||
if idx > start - take + 1:
|
||||
results.append('')
|
||||
return results
|
||||
|
||||
|
||||
def verse(number):
|
||||
return [
|
||||
*main_verse(number),
|
||||
"And if one green bottle should accidentally fall,",
|
||||
last_verse(number)
|
||||
]
|
||||
|
||||
def main_verse(number):
|
||||
if number == 1:
|
||||
return [
|
||||
f'One green bottle hanging on the wall,',
|
||||
f'One green bottle hanging on the wall,',
|
||||
]
|
||||
else:
|
||||
return [
|
||||
f'{NUMBERS[number].capitalize()} green bottles hanging on the wall,',
|
||||
f'{NUMBERS[number].capitalize()} green bottles hanging on the wall,',]
|
||||
|
||||
def last_verse(number):
|
||||
if number -1 == 1:
|
||||
return f"There'll be one green bottle hanging on the wall."
|
||||
else:
|
||||
return f"There'll be {NUMBERS[number-1]} green bottles hanging on the wall."
|
||||
23
exercises/practice/bottle-song/.meta/template.j2
Normal file
23
exercises/practice/bottle-song/.meta/template.j2
Normal file
@@ -0,0 +1,23 @@
|
||||
{%- import "generator_macros.j2" as macros with context -%}
|
||||
{{ macros.header() }}
|
||||
|
||||
class {{ exercise | camel_case }}Test(unittest.TestCase):
|
||||
{% for case in cases -%}
|
||||
{% for subcase in case["cases"] -%}
|
||||
{% for subsubcase in subcase["cases"] -%}
|
||||
def test_{{ subsubcase["description"] | to_snake }}(self):
|
||||
{% set start = subsubcase["input"]["startBottles"] -%}
|
||||
{% set take = subsubcase["input"]["takeDown"] -%}
|
||||
expected = {{ subsubcase["expected"] }}
|
||||
{%- if take == 1 %}
|
||||
self.assertEqual({{ subsubcase["property"] }}(start={{ start}}), expected)
|
||||
{% else %}
|
||||
self.assertEqual({{ subsubcase["property"] }}(start={{ start}}, take={{ take }}), expected)
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{{ macros.footer() }}
|
||||
31
exercises/practice/bottle-song/.meta/tests.toml
Normal file
31
exercises/practice/bottle-song/.meta/tests.toml
Normal file
@@ -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"
|
||||
2
exercises/practice/bottle-song/bottle_song.py
Normal file
2
exercises/practice/bottle-song/bottle_song.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def recite(start, take=1):
|
||||
pass
|
||||
136
exercises/practice/bottle-song/bottle_song_test.py
Normal file
136
exercises/practice/bottle-song/bottle_song_test.py
Normal file
@@ -0,0 +1,136 @@
|
||||
import unittest
|
||||
|
||||
from bottle_song import (
|
||||
recite,
|
||||
)
|
||||
|
||||
# Tests adapted from `problem-specifications//canonical-data.json`
|
||||
|
||||
|
||||
class BottleSongTest(unittest.TestCase):
|
||||
def test_first_generic_verse(self):
|
||||
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.",
|
||||
]
|
||||
self.assertEqual(recite(start=10), expected)
|
||||
|
||||
def test_last_generic_verse(self):
|
||||
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.",
|
||||
]
|
||||
self.assertEqual(recite(start=3), expected)
|
||||
|
||||
def test_verse_with_2_bottles(self):
|
||||
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.",
|
||||
]
|
||||
self.assertEqual(recite(start=2), expected)
|
||||
|
||||
def test_verse_with_1_bottle(self):
|
||||
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.",
|
||||
]
|
||||
self.assertEqual(recite(start=1), expected)
|
||||
|
||||
def test_first_two_verses(self):
|
||||
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.",
|
||||
]
|
||||
self.assertEqual(recite(start=10, take=2), expected)
|
||||
|
||||
def test_last_three_verses(self):
|
||||
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.",
|
||||
]
|
||||
self.assertEqual(recite(start=3, take=3), expected)
|
||||
|
||||
def test_all_verses(self):
|
||||
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.",
|
||||
]
|
||||
self.assertEqual(recite(start=10, take=10), expected)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user