diff --git a/bin/auto-sync.txt b/bin/auto-sync.txt index 217ece2d3..369058b19 100644 --- a/bin/auto-sync.txt +++ b/bin/auto-sync.txt @@ -71,6 +71,7 @@ robot-simulator roman-numerals rotational-cipher run-length-encoding +say scrabble-score secret-handshake sieve diff --git a/exercises/practice/say/.docs/instructions.md b/exercises/practice/say/.docs/instructions.md index a3f8f6906..3251c519a 100644 --- a/exercises/practice/say/.docs/instructions.md +++ b/exercises/practice/say/.docs/instructions.md @@ -1,50 +1,12 @@ -# Description +# Instructions -Given a number from 0 to 999,999,999,999, spell out that number in English. +Given a number, your task is to express it in English words exactly as your friend should say it out loud. +Yaʻqūb expects to use numbers from 0 up to 999,999,999,999. -## Step 1 +Examples: -Handle the basic case of 0 through 99. - -If the input to the program is `22`, then the output should be `'twenty-two'`. - -Your program should complain loudly if given a number outside the blessed range. - -Some good test cases for this program are: - -- 0 -- 14 -- 50 -- 98 -- -1 -- 100 - -### Extension - -If you're on a Mac, shell out to Mac OS X's `say` program to talk out loud. -If you're on Linux or Windows, eSpeakNG may be available with the command `espeak`. - -## Step 2 - -Implement breaking a number up into chunks of thousands. - -So `1234567890` should yield a list like 1, 234, 567, and 890, while the far simpler `1000` should yield just 1 and 0. - -The program must also report any values that are out of range. - -## Step 3 - -Now handle inserting the appropriate scale word between those chunks. - -So `1234567890` should yield `'1 billion 234 million 567 thousand 890'` - -The program must also report any values that are out of range. -It's fine to stop at "trillion". - -## Step 4 - -Put it all together to get nothing but plain English. - -`12345` should give `twelve thousand three hundred forty-five`. - -The program must also report any values that are out of range. +- 0 → zero +- 1 → one +- 12 → twelve +- 123 → one hundred twenty-three +- 1,234 → one thousand two hundred thirty-four diff --git a/exercises/practice/say/.docs/introduction.md b/exercises/practice/say/.docs/introduction.md new file mode 100644 index 000000000..abd22851e --- /dev/null +++ b/exercises/practice/say/.docs/introduction.md @@ -0,0 +1,6 @@ +# Introduction + +Your friend Yaʻqūb works the counter at the busiest deli in town, slicing, weighing, and wrapping orders for a never-ending line of hungry customers. +To keep things moving, each customer takes a numbered ticket when they arrive. + +When it’s time to call the next person, Yaʻqūb reads their number out loud, always in full English words to make sure everyone hears it clearly. diff --git a/exercises/practice/say/.meta/config.json b/exercises/practice/say/.meta/config.json index 0c0442512..65190cba9 100644 --- a/exercises/practice/say/.meta/config.json +++ b/exercises/practice/say/.meta/config.json @@ -2,6 +2,9 @@ "authors": [ "vnkmpf" ], + "contributors": [ + "resu-xuniL" + ], "files": { "solution": [ "Say.php" @@ -13,5 +16,7 @@ ".meta/example.php" ] }, - "blurb": "Given a number from 0 to 999,999,999,999, spell out that number in English." + "blurb": "Given a number from 0 to 999,999,999,999, spell out that number in English.", + "source": "A variation on the JavaRanch CattleDrive, Assignment 4", + "source_url": "https://web.archive.org/web/20240907035912/https://coderanch.com/wiki/718804" } diff --git a/exercises/practice/say/.meta/example.php b/exercises/practice/say/.meta/example.php index e8300e4e4..3d71b6cf8 100644 --- a/exercises/practice/say/.meta/example.php +++ b/exercises/practice/say/.meta/example.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); function say(int $number): string diff --git a/exercises/practice/say/.meta/tests.toml b/exercises/practice/say/.meta/tests.toml new file mode 100644 index 000000000..a5532e9ed --- /dev/null +++ b/exercises/practice/say/.meta/tests.toml @@ -0,0 +1,67 @@ +# 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. + +[5d22a120-ba0c-428c-bd25-8682235d83e8] +description = "zero" + +[9b5eed77-dbf6-439d-b920-3f7eb58928f6] +description = "one" + +[7c499be1-612e-4096-a5e1-43b2f719406d] +description = "fourteen" + +[f541dd8e-f070-4329-92b4-b7ce2fcf06b4] +description = "twenty" + +[d78601eb-4a84-4bfa-bf0e-665aeb8abe94] +description = "twenty-two" + +[f010d4ca-12c9-44e9-803a-27789841adb1] +description = "thirty" + +[738ce12d-ee5c-4dfb-ad26-534753a98327] +description = "ninety-nine" + +[e417d452-129e-4056-bd5b-6eb1df334dce] +description = "one hundred" + +[d6924f30-80ba-4597-acf6-ea3f16269da8] +description = "one hundred twenty-three" + +[2f061132-54bc-4fd4-b5df-0a3b778959b9] +description = "two hundred" + +[feed6627-5387-4d38-9692-87c0dbc55c33] +description = "nine hundred ninety-nine" + +[3d83da89-a372-46d3-b10d-de0c792432b3] +description = "one thousand" + +[865af898-1d5b-495f-8ff0-2f06d3c73709] +description = "one thousand two hundred thirty-four" + +[b6a3f442-266e-47a3-835d-7f8a35f6cf7f] +description = "one million" + +[2cea9303-e77e-4212-b8ff-c39f1978fc70] +description = "one million two thousand three hundred forty-five" + +[3e240eeb-f564-4b80-9421-db123f66a38f] +description = "one billion" + +[9a43fed1-c875-4710-8286-5065d73b8a9e] +description = "a big number" + +[49a6a17b-084e-423e-994d-a87c0ecc05ef] +description = "numbers below zero are out of range" + +[4d6492eb-5853-4d16-9d34-b0f61b261fd9] +description = "numbers above 999,999,999,999 are out of range" diff --git a/exercises/practice/say/SayTest.php b/exercises/practice/say/SayTest.php index e88353b28..0724da4e4 100644 --- a/exercises/practice/say/SayTest.php +++ b/exercises/practice/say/SayTest.php @@ -1,30 +1,9 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\TestDox; class SayTest extends TestCase { @@ -33,76 +12,136 @@ public static function setUpBeforeClass(): void require_once 'Say.php'; } + /** + * uuid 5d22a120-ba0c-428c-bd25-8682235d83e8 + */ + #[TestDox('zero')] public function testZero(): void { $this->assertEquals('zero', say(0)); } + /** + * uuid 9b5eed77-dbf6-439d-b920-3f7eb58928f6 + */ + #[TestDox('one')] public function testOne(): void { $this->assertEquals('one', say(1)); } + /** + * uuid 7c499be1-612e-4096-a5e1-43b2f719406d + */ + #[TestDox('fourteen')] public function testFourteen(): void { $this->assertEquals('fourteen', say(14)); } + /** + * uuid f541dd8e-f070-4329-92b4-b7ce2fcf06b4 + */ + #[TestDox('twenty')] public function testTwenty(): void { $this->assertEquals('twenty', say(20)); } + /** + * uuid d78601eb-4a84-4bfa-bf0e-665aeb8abe94 + */ + #[TestDox('twenty-two')] public function testTwentyTwo(): void { $this->assertEquals('twenty-two', say(22)); } + /** + * uuid f010d4ca-12c9-44e9-803a-27789841adb1 + */ + #[TestDox('thirty')] public function testThirty(): void { $this->assertEquals('thirty', say(30)); } + /** + * uuid 738ce12d-ee5c-4dfb-ad26-534753a98327 + */ + #[TestDox('ninety-nine')] public function testNinetyNine(): void { $this->assertEquals('ninety-nine', say(99)); } + /** + * uuid e417d452-129e-4056-bd5b-6eb1df334dce + */ + #[TestDox('one hundred')] public function testOneHundred(): void { $this->assertEquals('one hundred', say(100)); } + /** + * uuid d6924f30-80ba-4597-acf6-ea3f16269da8 + */ + #[TestDox('one hundred twenty-three')] public function testOneHundredTwentyThree(): void { $this->assertEquals('one hundred twenty-three', say(123)); } + /** + * uuid 2f061132-54bc-4fd4-b5df-0a3b778959b9 + */ + #[TestDox('two hundred')] public function testTwoHundred(): void { $this->assertEquals('two hundred', say(200)); } + /** + * uuid feed6627-5387-4d38-9692-87c0dbc55c33 + */ + #[TestDox('nine hundred ninety-nine')] public function testNineHundredNinetyNine(): void { $this->assertEquals('nine hundred ninety-nine', say(999)); } + /** + * uuid 3d83da89-a372-46d3-b10d-de0c792432b3 + */ + #[TestDox('one thousand')] public function testOneThousand(): void { $this->assertEquals('one thousand', say(1000)); } + /** + * uuid 865af898-1d5b-495f-8ff0-2f06d3c73709 + */ + #[TestDox('one thousand two hundred thirty-four')] public function testOneThousandTwoHundredThirtyFour(): void { $this->assertEquals('one thousand two hundred thirty-four', say(1234)); } + /** + * uuid b6a3f442-266e-47a3-835d-7f8a35f6cf7f + */ + #[TestDox('one million')] public function testOneMillion(): void { $this->assertEquals('one million', say(1_000_000)); } + /** + * uuid 2cea9303-e77e-4212-b8ff-c39f1978fc70 + */ + #[TestDox('one million two thousand three hundred forty-five')] public function testOneMillionTwoThousandThreeHundredFortyFive(): void { $this->assertEquals( @@ -111,11 +150,19 @@ public function testOneMillionTwoThousandThreeHundredFortyFive(): void ); } + /** + * uuid 3e240eeb-f564-4b80-9421-db123f66a38f + */ + #[TestDox('one billion')] public function testOneBillion(): void { $this->assertEquals('one billion', say(1_000_000_000)); } + /** + * uuid 9a43fed1-c875-4710-8286-5065d73b8a9e + */ + #[TestDox('a big number')] public function testABigNumber(): void { $this->assertEquals( @@ -125,6 +172,10 @@ public function testABigNumber(): void ); } + /** + * uuid 49a6a17b-084e-423e-994d-a87c0ecc05ef + */ + #[TestDox('numbers below zero are out of range')] public function testNumbersBelowZeroAreOutOfRange(): void { $this->expectException(InvalidArgumentException::class); @@ -133,6 +184,10 @@ public function testNumbersBelowZeroAreOutOfRange(): void say(-1); } + /** + * uuid 4d6492eb-5853-4d16-9d34-b0f61b261fd9 + */ + #[TestDox('numbers above 999,999,999,999 are out of range')] public function testNumbersAbove999999999999AreOutOfRange(): void { $this->expectException(InvalidArgumentException::class);