Frédéric G. MARAND 7 месяцев назад
Родитель
Сommit
4f36c3ec7f
6 измененных файлов с 282 добавлено и 0 удалено
  1. 26 0
      pangram/.exercism/config.json
  2. 1 0
      pangram/.exercism/metadata.json
  3. 52 0
      pangram/HELP.md
  4. 42 0
      pangram/Pangram.php
  5. 113 0
      pangram/PangramTest.php
  6. 48 0
      pangram/README.md

+ 26 - 0
pangram/.exercism/config.json

@@ -0,0 +1,26 @@
+{
+  "authors": [
+    "ecrmnn"
+  ],
+  "contributors": [
+    "arueckauer",
+    "kunicmarko20",
+    "kytrinyx",
+    "petemcfarlane",
+    "rossbearman"
+  ],
+  "files": {
+    "solution": [
+      "Pangram.php"
+    ],
+    "test": [
+      "PangramTest.php"
+    ],
+    "example": [
+      ".meta/example.php"
+    ]
+  },
+  "blurb": "Determine if a sentence is a pangram.",
+  "source": "Wikipedia",
+  "source_url": "https://en.wikipedia.org/wiki/Pangram"
+}

+ 1 - 0
pangram/.exercism/metadata.json

@@ -0,0 +1 @@
+{"track":"php","exercise":"pangram","id":"ababfbdba39f4d44b5cd846f94132b62","url":"https://exercism.org/tracks/php/exercises/pangram","handle":"Fairgame","is_requester":true,"auto_approve":false}

+ 52 - 0
pangram/HELP.md

@@ -0,0 +1,52 @@
+# Help
+
+## Running the tests
+
+## Running the tests
+
+1. Go to the root of your PHP exercise directory, which is `<EXERCISM_WORKSPACE>/php`.
+   To find the Exercism workspace run
+
+       ➜ exercism debug | grep Workspace
+
+1. Get [PHPUnit] if you don't have it already.
+
+       ➜ wget -O phpunit https://phar.phpunit.de/phpunit-9.phar
+       ➜ chmod +x phpunit
+       ➜ ./phpunit --version
+
+2. Execute the tests:
+
+       ➜ ./phpunit file_to_test.php
+
+   For example, to run the tests for the Hello World exercise, you would run:
+
+       ➜ ./phpunit HelloWorldTest.php
+
+[PHPUnit]: https://phpunit.de
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit Pangram.php` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [PHP track's documentation](https://exercism.org/docs/tracks/php)
+- The [PHP track's programming category on the forum](https://forum.exercism.org/c/programming/php)
+- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+ - [/r/php](https://www.reddit.com/r/php) is the PHP subreddit.
+ - [StackOverflow](https://stackoverflow.com/questions/tagged/php) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.

+ 42 - 0
pangram/Pangram.php

@@ -0,0 +1,42 @@
+<?php
+
+/*
+ * By adding type hints and enabling strict type checking, code can become
+ * easier to read, self-documenting and reduce the number of potential bugs.
+ * By default, type declarations are non-strict, which means they will attempt
+ * to change the original type to match the type specified by the
+ * type-declaration.
+ *
+ * In other words, if you pass a string to a function requiring a float,
+ * it will attempt to convert the string value to a float.
+ *
+ * To enable strict mode, a single declare directive must be placed at the top
+ * of the file.
+ * This means that the strictness of typing is configured on a per-file basis.
+ * This directive not only affects the type declarations of parameters, but also
+ * a function's return type.
+ *
+ * For more info review the Concept on strict type checking in the PHP track
+ * <link>.
+ *
+ * To disable strict typing, comment out the directive below.
+ */
+
+declare(strict_types=1);
+
+function buildLetters(): array {
+  $letters = [];
+  $base = ord('A');
+  for ($i = 0; $i <= 25; $i++) {
+    $letters[chr($base+$i)] = TRUE;
+  }
+  return $letters;
+}
+
+function isPangram(string $string): bool {
+  $letters = buildLetters();
+  foreach (mb_str_split(mb_strtoupper($string)) as $letter) {
+    unset($letters[$letter]);
+  }
+  return empty($letters);
+}

+ 113 - 0
pangram/PangramTest.php

@@ -0,0 +1,113 @@
+<?php
+
+declare(strict_types=1);
+
+class PangramTest extends PHPUnit\Framework\TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        require_once 'Pangram.php';
+    }
+
+    /**
+     * uuid 64f61791-508e-4f5c-83ab-05de042b0149
+     * @testdox Empty sentence
+     */
+    public function testSentenceEmpty(): void
+    {
+        $this->assertFalse(isPangram(''));
+    }
+
+    /**
+     * uuid 74858f80-4a4d-478b-8a5e-c6477e4e4e84
+     * @testdox Perfect lower case
+     */
+    public function testPerfectLowerCase(): void
+    {
+        $this->assertTrue(isPangram('abcdefghijklmnopqrstuvwxyz'));
+    }
+
+    /**
+     * uuid 61288860-35ca-4abe-ba08-f5df76ecbdcd
+     * @testdox Only lower case
+     */
+    public function testPangramWithOnlyLowerCase(): void
+    {
+        $this->assertTrue(isPangram('the quick brown fox jumps over the lazy dog'));
+    }
+
+    /**
+     * uuid 6564267d-8ac5-4d29-baf2-e7d2e304a743
+     * @testdox Missing the letter 'x'
+     */
+    public function testMissingCharacterX(): void
+    {
+        $this->assertFalse(isPangram('a quick movement of the enemy will jeopardize five gunboats'));
+    }
+
+    /**
+     * uuid c79af1be-d715-4cdb-a5f2-b2fa3e7e0de0
+     * @testdox Missing the letter 'h'
+     */
+    public function testMissingCharacterH(): void
+    {
+        $this->assertFalse(isPangram('five boxing wizards jump quickly at it'));
+    }
+
+    /**
+     * uuid d835ec38-bc8f-48e4-9e36-eb232427b1df
+     * @testdox With underscores
+     */
+    public function testPangramWithUnderscores(): void
+    {
+        $this->assertTrue(isPangram('the_quick_brown_fox_jumps_over_the_lazy_dog'));
+    }
+
+    /**
+     * uuid 8cc1e080-a178-4494-b4b3-06982c9be2a8
+     * @testdox With numbers
+     */
+    public function testPangramWithNumbers(): void
+    {
+        $this->assertTrue(isPangram('the 1 quick brown fox jumps over the 2 lazy dogs'));
+    }
+
+    /**
+     * uuid bed96b1c-ff95-45b8-9731-fdbdcb6ede9a
+     * @testdox Missing letters replaced by numbers
+     */
+    public function testMissingLettersReplacedByNumbers(): void
+    {
+        $this->assertFalse(isPangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog'));
+    }
+
+    /**
+     * uuid 938bd5d8-ade5-40e2-a2d9-55a338a01030
+     * @testdox Mixed case and punctuation
+     */
+    public function testPangramWithMixedCaseAndPunctuation(): void
+    {
+        $this->assertTrue(isPangram('"Five quacking Zephyrs jolt my wax bed."'));
+    }
+
+    /**
+     * uuid 7138e389-83e4-4c6e-8413-1e40a0076951
+     * @testdox a-m and A-M are 26 different characters but not a pangram
+     */
+    public function testEnoughDifferentCharsButOnlyCaseDiffers(): void
+    {
+        $this->assertFalse(isPangram('abcdefghijklm ABCDEFGHIJKLM'));
+    }
+
+    /*
+     * PHP track addons
+     */
+
+    /**
+     * @testdox Unicode mixed into pangram
+     */
+    public function testPangramMixedWithUnicode(): void
+    {
+        $this->assertTrue(isPangram('Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.'));
+    }
+}

+ 48 - 0
pangram/README.md

@@ -0,0 +1,48 @@
+# Pangram
+
+Welcome to Pangram on Exercism's PHP Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Introduction
+
+You work for a company that sells fonts through their website.
+They'd like to show a different sentence each time someone views a font on their website.
+To give a comprehensive sense of the font, the random sentences should use **all** the letters in the English alphabet.
+
+They're running a competition to get suggestions for sentences that they can use.
+You're in charge of checking the submissions to see if they are valid.
+
+~~~~exercism/note
+Pangram comes from Greek, παν γράμμα, pan gramma, which means "every letter".
+
+The best known English pangram is:
+
+> The quick brown fox jumps over the lazy dog.
+~~~~
+
+## Instructions
+
+Your task is to figure out if a sentence is a pangram.
+
+A pangram is a sentence using every letter of the alphabet at least once.
+It is case insensitive, so it doesn't matter if a letter is lower-case (e.g. `k`) or upper-case (e.g. `K`).
+
+For this exercise, a sentence is a pangram if it contains each of the 26 letters in the English alphabet.
+
+## Source
+
+### Created by
+
+- @ecrmnn
+
+### Contributed to by
+
+- @arueckauer
+- @kunicmarko20
+- @kytrinyx
+- @petemcfarlane
+- @rossbearman
+
+### Based on
+
+Wikipedia - https://en.wikipedia.org/wiki/Pangram