diff --git a/exercises/practice/ordinal-number/.docs/instructions.md b/exercises/practice/ordinal-number/.docs/instructions.md new file mode 100644 index 00000000..0653ca10 --- /dev/null +++ b/exercises/practice/ordinal-number/.docs/instructions.md @@ -0,0 +1,21 @@ +# Instructions + +Write a function to convert normal numbers to [ordinal numbers](https://en.wikipedia.org/wiki/Ordinal_numeral). For zero (0) just return "0" as string. + +Ordinal number are numbers that describe the position of something in a list. +It is this context that ordinal numbers will be used, using an English-spelled name of an ordinal number. + +The ordinal numbers are (at least, one form of them): + +``` +1st 2nd 3rd 4th 5th... 9th 10th 11th 12th... 20th 21st 22nd 23rd 24th... etc. +``` + +So entering a normal number results in its ordinal equivalent: + +``` +1 -> 1st +2 -> 2nd +3 -> 3rd +(and so on...) +``` diff --git a/exercises/practice/ordinal-number/.meta/config.json b/exercises/practice/ordinal-number/.meta/config.json new file mode 100644 index 00000000..f6379c8e --- /dev/null +++ b/exercises/practice/ordinal-number/.meta/config.json @@ -0,0 +1,27 @@ +{ + "authors": [ + { + "github_username": "codedge", + "exercism_username": "codedge" + } + ], + "contributors": [ + { + "github_username": "neenjaw", + "exercism_username": "neenjaw" + } + ], + "files": { + "solution": [ + "OrdinalNumber.php" + ], + "test": [ + "OrdinalNumberTest.php" + ], + "example": [ + ".meta/example.php" + ] + }, + "source": "", + "source_url": "https://en.wikipedia.org/wiki/Ordinal_numeral" +} diff --git a/exercises/practice/ordinal-number/.meta/example.php b/exercises/practice/ordinal-number/.meta/example.php new file mode 100644 index 00000000..5d422e16 --- /dev/null +++ b/exercises/practice/ordinal-number/.meta/example.php @@ -0,0 +1,26 @@ +assertEquals('0', toOrdinal(0)); + } + + public function testFirst(): void + { + $this->assertEquals('1st', toOrdinal(1)); + } + + public function testSecond(): void + { + $this->assertEquals('2nd', toOrdinal(2)); + } + + public function testThird(): void + { + $this->assertEquals('3rd', toOrdinal(3)); + } + + public function testFourth(): void + { + $this->assertEquals('4th', toOrdinal(4)); + } + + public function testTenth(): void + { + $this->assertEquals('10th', toOrdinal(10)); + } + + public function testEleventh(): void + { + $this->assertEquals('11th', toOrdinal(11)); + } + + public function testTwelfth(): void + { + $this->assertEquals('12th', toOrdinal(12)); + } + + public function testThirteenth(): void + { + $this->assertEquals('13th', toOrdinal(13)); + } + + public function testRandomNumber(): void + { + $this->assertEquals('62nd', toOrdinal(62)); + } +}