From a7882c20bcd4276ad85d45774fd40eb8b57de8ce Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Wed, 28 Feb 2024 12:41:36 +0100 Subject: [PATCH] Add House Exercise (#647) --- config.json | 8 + .../practice/house/.docs/instructions.md | 105 +++++ exercises/practice/house/.meta/config.json | 19 + exercises/practice/house/.meta/example.php | 71 ++++ exercises/practice/house/.meta/tests.toml | 52 +++ exercises/practice/house/House.php | 38 ++ exercises/practice/house/HouseTest.php | 361 ++++++++++++++++++ 7 files changed, 654 insertions(+) create mode 100644 exercises/practice/house/.docs/instructions.md create mode 100644 exercises/practice/house/.meta/config.json create mode 100644 exercises/practice/house/.meta/example.php create mode 100644 exercises/practice/house/.meta/tests.toml create mode 100644 exercises/practice/house/House.php create mode 100644 exercises/practice/house/HouseTest.php diff --git a/config.json b/config.json index ab0bbf84..f13890aa 100644 --- a/config.json +++ b/config.json @@ -1112,6 +1112,14 @@ "conditionals" ] }, + { + "slug": "house", + "name": "House", + "uuid": "76a067bc-5bc3-47de-a539-69eb6c80473a", + "practices": [], + "prerequisites": [], + "difficulty": 3 + }, { "slug": "scale-generator", "name": "Scale Generator", diff --git a/exercises/practice/house/.docs/instructions.md b/exercises/practice/house/.docs/instructions.md new file mode 100644 index 00000000..b8a657da --- /dev/null +++ b/exercises/practice/house/.docs/instructions.md @@ -0,0 +1,105 @@ +# Instructions + +Recite the nursery rhyme 'This is the House that Jack Built'. + +> The process of placing a phrase of clause within another phrase of clause is called embedding. +> It is through the processes of recursion and embedding that we are able to take a finite number of forms (words and phrases) and construct an infinite number of expressions. +> Furthermore, embedding also allows us to construct an infinitely long structure, in theory anyway. + +- [papyr.com][papyr] + +The nursery rhyme reads as follows: + +```text +This is the house that Jack built. + +This is the malt +that lay in the house that Jack built. + +This is the rat +that ate the malt +that lay in the house that Jack built. + +This is the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the cow with the crumpled horn +that tossed the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the maiden all forlorn +that milked the cow with the crumpled horn +that tossed the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the man all tattered and torn +that kissed the maiden all forlorn +that milked the cow with the crumpled horn +that tossed the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the priest all shaven and shorn +that married the man all tattered and torn +that kissed the maiden all forlorn +that milked the cow with the crumpled horn +that tossed the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the rooster that crowed in the morn +that woke the priest all shaven and shorn +that married the man all tattered and torn +that kissed the maiden all forlorn +that milked the cow with the crumpled horn +that tossed the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the farmer sowing his corn +that kept the rooster that crowed in the morn +that woke the priest all shaven and shorn +that married the man all tattered and torn +that kissed the maiden all forlorn +that milked the cow with the crumpled horn +that tossed the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. + +This is the horse and the hound and the horn +that belonged to the farmer sowing his corn +that kept the rooster that crowed in the morn +that woke the priest all shaven and shorn +that married the man all tattered and torn +that kissed the maiden all forlorn +that milked the cow with the crumpled horn +that tossed the dog +that worried the cat +that killed the rat +that ate the malt +that lay in the house that Jack built. +``` + +[papyr]: https://papyr.com/hypertextbooks/grammar/ph_noun.htm diff --git a/exercises/practice/house/.meta/config.json b/exercises/practice/house/.meta/config.json new file mode 100644 index 00000000..2c179d04 --- /dev/null +++ b/exercises/practice/house/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "tomasnorre" + ], + "files": { + "solution": [ + "House.php" + ], + "test": [ + "HouseTest.php" + ], + "example": [ + ".meta/example.php" + ] + }, + "blurb": "Output the nursery rhyme 'This is the House that Jack Built'.", + "source": "British nursery rhyme", + "source_url": "https://en.wikipedia.org/wiki/This_Is_The_House_That_Jack_Built" +} diff --git a/exercises/practice/house/.meta/example.php b/exercises/practice/house/.meta/example.php new file mode 100644 index 00000000..d485af9f --- /dev/null +++ b/exercises/practice/house/.meta/example.php @@ -0,0 +1,71 @@ +verse($i); + $lines = array_merge($lines, $verseLines); + if ($i < $end) { + $lines[] = ''; + } + } + return $lines; + } +} diff --git a/exercises/practice/house/.meta/tests.toml b/exercises/practice/house/.meta/tests.toml new file mode 100644 index 00000000..da24dc3a --- /dev/null +++ b/exercises/practice/house/.meta/tests.toml @@ -0,0 +1,52 @@ +# 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. + +[28a540ff-f765-4348-9d57-ae33f25f41f2] +description = "verse one - the house that jack built" + +[ebc825ac-6e2b-4a5e-9afd-95732191c8da] +description = "verse two - the malt that lay" + +[1ed8bb0f-edb8-4bd1-b6d4-b64754fe4a60] +description = "verse three - the rat that ate" + +[64b0954e-8b7d-4d14-aad0-d3f6ce297a30] +description = "verse four - the cat that killed" + +[1e8d56bc-fe31-424d-9084-61e6111d2c82] +description = "verse five - the dog that worried" + +[6312dc6f-ab0a-40c9-8a55-8d4e582beac4] +description = "verse six - the cow with the crumpled horn" + +[68f76d18-6e19-4692-819c-5ff6a7f92feb] +description = "verse seven - the maiden all forlorn" + +[73872564-2004-4071-b51d-2e4326096747] +description = "verse eight - the man all tattered and torn" + +[0d53d743-66cb-4351-a173-82702f3338c9] +description = "verse nine - the priest all shaven and shorn" + +[452f24dc-8fd7-4a82-be1a-3b4839cfeb41] +description = "verse 10 - the rooster that crowed in the morn" + +[97176f20-2dd3-4646-ac72-cffced91ea26] +description = "verse 11 - the farmer sowing his corn" + +[09824c29-6aad-4dcd-ac98-f61374a6a8b7] +description = "verse 12 - the horse and the hound and the horn" + +[d2b980d3-7851-49e1-97ab-1524515ec200] +description = "multiple verses" + +[0311d1d0-e085-4f23-8ae7-92406fb3e803] +description = "full rhyme" diff --git a/exercises/practice/house/House.php b/exercises/practice/house/House.php new file mode 100644 index 00000000..57c187a2 --- /dev/null +++ b/exercises/practice/house/House.php @@ -0,0 +1,38 @@ +. + * + * To disable strict typing, comment out the directive below. + */ + +declare(strict_types=1); + +class House +{ + public function verse(int $verseNumber): array + { + throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); + } + + public function verses(int $start, int $end): array + { + throw new \BadMethodCallException(sprintf('Implement the %s method', __FUNCTION__)); + } +} diff --git a/exercises/practice/house/HouseTest.php b/exercises/practice/house/HouseTest.php new file mode 100644 index 00000000..65aa1eb1 --- /dev/null +++ b/exercises/practice/house/HouseTest.php @@ -0,0 +1,361 @@ +house = new House(); + } + + /** + * uuid: 28a540ff-f765-4348-9d57-ae33f25f41f2 + */ + public function testVerseOne(): void + { + $lyrics = ['This is the house that Jack built.']; + $this->assertEquals($lyrics, $this->house->verse(1)); + } + + /** + * uuid: ebc825ac-6e2b-4a5e-9afd-95732191c8da + */ + public function testVerseTwo(): void + { + $lyrics = [ + 'This is the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(2)); + } + + /** + * uuid: 1ed8bb0f-edb8-4bd1-b6d4-b64754fe4a60 + */ + public function testVerseThree(): void + { + $lyrics = [ + 'This is the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(3)); + } + + /** + * uuid: 64b0954e-8b7d-4d14-aad0-d3f6ce297a30 + */ + public function testVerseFour(): void + { + $lyrics = [ + 'This is the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(4)); + } + + /** + * uuid: 1e8d56bc-fe31-424d-9084-61e6111d2c82 + */ + public function testVerseFive(): void + { + $lyrics = [ + 'This is the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(5)); + } + + /** + * uuid: 6312dc6f-ab0a-40c9-8a55-8d4e582beac4 + */ + public function testVerseSix(): void + { + $lyrics = [ + 'This is the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(6)); + } + + /** + * uuid: 68f76d18-6e19-4692-819c-5ff6a7f92feb + */ + public function testVerseSeven(): void + { + $lyrics = [ + 'This is the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(7)); + } + + /** + * uuid: 73872564-2004-4071-b51d-2e4326096747 + */ + public function testVerseEight(): void + { + $lyrics = [ + 'This is the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(8)); + } + + /** + * uuid: 0d53d743-66cb-4351-a173-82702f3338c9 + */ + public function testVerseNine(): void + { + $lyrics = [ + 'This is the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(9)); + } + + /** + * uuid: 452f24dc-8fd7-4a82-be1a-3b4839cfeb41 + */ + public function testVerseTen(): void + { + $lyrics = [ + 'This is the rooster that crowed in the morn', + 'that woke the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(10)); + } + + /** + * uuid: 97176f20-2dd3-4646-ac72-cffced91ea26 + */ + public function testVerseEleven(): void + { + $lyrics = [ + 'This is the farmer sowing his corn', + 'that kept the rooster that crowed in the morn', + 'that woke the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(11)); + } + + /** + * uuid: 09824c29-6aad-4dcd-ac98-f61374a6a8b7 + */ + public function testVerseTwelve(): void + { + $lyrics = [ + 'This is the horse and the hound and the horn', + 'that belonged to the farmer sowing his corn', + 'that kept the rooster that crowed in the morn', + 'that woke the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verse(12)); + } + + /** + * uuid: d2b980d3-7851-49e1-97ab-1524515ec200 + */ + public function testMultipleVerses(): void + { + $startVerse = 4; + $endVerse = 8; + $lyrics = [ + 'This is the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verses($startVerse, $endVerse)); + } + + /** + * uuid: 0311d1d0-e085-4f23-8ae7-92406fb3e803 + */ + public function testFullRhyme(): void + { + $startVerse = 1; + $endVerse = 12; + $lyrics = [ + 'This is the house that Jack built.', + '', + 'This is the malt', + 'that lay in the house that Jack built.', + '', + 'This is the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the rooster that crowed in the morn', + 'that woke the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the farmer sowing his corn', + 'that kept the rooster that crowed in the morn', + 'that woke the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + '', + 'This is the horse and the hound and the horn', + 'that belonged to the farmer sowing his corn', + 'that kept the rooster that crowed in the morn', + 'that woke the priest all shaven and shorn', + 'that married the man all tattered and torn', + 'that kissed the maiden all forlorn', + 'that milked the cow with the crumpled horn', + 'that tossed the dog', + 'that worried the cat', + 'that killed the rat', + 'that ate the malt', + 'that lay in the house that Jack built.', + ]; + $this->assertEquals($lyrics, $this->house->verses($startVerse, $endVerse)); + } +}