diff --git a/exercises/practice/prime-factors/.docs/instructions.md b/exercises/practice/prime-factors/.docs/instructions.md index b5cb1657..252cc8ee 100644 --- a/exercises/practice/prime-factors/.docs/instructions.md +++ b/exercises/practice/prime-factors/.docs/instructions.md @@ -10,21 +10,27 @@ Note that 1 is not a prime number. What are the prime factors of 60? -- Our first divisor is 2. 2 goes into 60, leaving 30. +- Our first divisor is 2. + 2 goes into 60, leaving 30. - 2 goes into 30, leaving 15. - - 2 doesn't go cleanly into 15. So let's move on to our next divisor, 3. + - 2 doesn't go cleanly into 15. + So let's move on to our next divisor, 3. - 3 goes cleanly into 15, leaving 5. - - 3 does not go cleanly into 5. The next possible factor is 4. - - 4 does not go cleanly into 5. The next possible factor is 5. + - 3 does not go cleanly into 5. + The next possible factor is 4. + - 4 does not go cleanly into 5. + The next possible factor is 5. - 5 does go cleanly into 5. - We're left only with 1, so now, we're done. -Our successful divisors in that computation represent the list of prime -factors of 60: 2, 2, 3, and 5. +Our successful divisors in that computation represent the list of prime factors of 60: 2, 2, 3, and 5. You can check this yourself: -- 2 * 2 * 3 * 5 -- = 4 * 15 -- = 60 -- Success! +```text +2 * 2 * 3 * 5 += 4 * 15 += 60 +``` + +Success! diff --git a/exercises/practice/prime-factors/.meta/config.json b/exercises/practice/prime-factors/.meta/config.json index 44ed0537..8b6e6bd4 100644 --- a/exercises/practice/prime-factors/.meta/config.json +++ b/exercises/practice/prime-factors/.meta/config.json @@ -7,7 +7,8 @@ "kunicmarko20", "kytrinyx", "petemcfarlane", - "yisraeldov" + "yisraeldov", + "Narkunan" ], "files": { "solution": [ @@ -22,5 +23,5 @@ }, "blurb": "Compute the prime factors of a given natural number.", "source": "The Prime Factors Kata by Uncle Bob", - "source_url": "https://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata" + "source_url": "https://web.archive.org/web/20221026171801/http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata" } diff --git a/exercises/practice/prime-factors/.meta/example.php b/exercises/practice/prime-factors/.meta/example.php index 7a817641..90198824 100644 --- a/exercises/practice/prime-factors/.meta/example.php +++ b/exercises/practice/prime-factors/.meta/example.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); function factors($n) diff --git a/exercises/practice/prime-factors/.meta/tests.toml b/exercises/practice/prime-factors/.meta/tests.toml index f3f05a3e..6f9cc8ce 100644 --- a/exercises/practice/prime-factors/.meta/tests.toml +++ b/exercises/practice/prime-factors/.meta/tests.toml @@ -1,6 +1,13 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# 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. [924fc966-a8f5-4288-82f2-6b9224819ccd] description = "no factors" @@ -8,12 +15,27 @@ description = "no factors" [17e30670-b105-4305-af53-ddde182cb6ad] description = "prime number" +[238d57c8-4c12-42ef-af34-ae4929f94789] +description = "another prime number" + [f59b8350-a180-495a-8fb1-1712fbee1158] description = "square of a prime" +[756949d3-3158-4e3d-91f2-c4f9f043ee70] +description = "product of first prime" + [bc8c113f-9580-4516-8669-c5fc29512ceb] description = "cube of a prime" +[7d6a3300-a4cb-4065-bd33-0ced1de6cb44] +description = "product of second prime" + +[073ac0b2-c915-4362-929d-fc45f7b9a9e4] +description = "product of third prime" + +[6e0e4912-7fb6-47f3-a9ad-dbcd79340c75] +description = "product of first and second prime" + [00485cd3-a3fe-4fbe-a64a-a4308fc1f870] description = "product of primes and non-primes" diff --git a/exercises/practice/prime-factors/PrimeFactorsTest.php b/exercises/practice/prime-factors/PrimeFactorsTest.php index d564a028..cf6c8c4f 100644 --- a/exercises/practice/prime-factors/PrimeFactorsTest.php +++ b/exercises/practice/prime-factors/PrimeFactorsTest.php @@ -1,29 +1,8 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; class PrimeFactorsTest extends TestCase @@ -33,37 +12,110 @@ public static function setUpBeforeClass(): void require_once 'PrimeFactors.php'; } + /** + * uuid: 924fc966-a8f5-4288-82f2-6b9224819ccd + */ + #[TestDox('no factors')] public function testNoFactors(): void { $this->assertSame([], factors(1)); } + /** + * uuid: 17e30670-b105-4305-af53-ddde182cb6ad + */ + #[TestDox('prime number')] public function testOneFactor(): void { $this->assertSame([2], factors(2)); } - public function testSquareOfPrime(): void + /** + * uuid: 238d57c8-4c12-42ef-af34-ae4929f94789 + */ + #[TestDox('another prime number')] + public function testAnotherPrimeNumber(): void + { + $this->assertSame([3], factors(3)); + } + + /** + * uuid: f59b8350-a180-495a-8fb1-1712fbee1158 + */ + #[TestDox('square of a prime')] + public function testSquareOfAPrime(): void { $this->assertSame([3, 3], factors(9)); } - public function testCubeOfPrime(): void + /** + * uuid: 756949d3-3158-4e3d-91f2-c4f9f043ee70 + */ + #[TestDox('product of first prime')] + public function testProductOfFirstPrime(): void + { + $this->assertSame([2, 2], factors(4)); + } + + /** + * uuid: bc8c113f-9580-4516-8669-c5fc29512ceb + */ + #[TestDox('cube of a prime')] + public function testCubeOfAPrime(): void { $this->assertSame([2, 2, 2], factors(8)); } - public function testProductOfPrimesAndNon(): void + /** + * uuid: 7d6a3300-a4cb-4065-bd33-0ced1de6cb44 + */ + #[TestDox('product of second prime')] + public function testProductOfSecondPrime(): void + { + $this->assertSame([3, 3, 3], factors(27)); + } + + /** + * uuid: 073ac0b2-c915-4362-929d-fc45f7b9a9e4 + */ + #[TestDox('product of third prime')] + public function testProductOfThirdPrime(): void + { + $this->assertSame([5, 5, 5, 5], factors(625)); + } + + /** + * uuid: 6e0e4912-7fb6-47f3-a9ad-dbcd79340c75 + */ + #[TestDox('product of first and second prime')] + public function testProductOfFirstAndSecondPrime(): void + { + $this->assertEquals([2, 3], factors(6)); + } + + /** + * uuid: 00485cd3-a3fe-4fbe-a64a-a4308fc1f870 + */ + #[TestDox('product of primes and non-primes')] + public function testProductOfPrimesAndNonPrimes(): void { $this->assertEquals([2, 2, 3], factors(12)); } + /** + * uuid: 02251d54-3ca1-4a9b-85e1-b38f4b0ccb91 + */ + #[TestDox('product of primes')] public function testProductOfPrimes(): void { $this->assertEquals([5, 17, 23, 461], factors(901255)); } - public function testFactorsIncludeLargePrime(): void + /** + * uuid: 070cf8dc-e202-4285-aa37-8d775c9cd473 + */ + #[TestDox('factors include a large prime')] + public function testFactorsIncludeALargePrime(): void { $this->assertEquals([11, 9539, 894119], factors(93819012551)); }