Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.81 KB | None | 0 0
  1. <?php
  2.  
  3. class AnagramTest extends PHPUnit\Framework\TestCase
  4. {
  5.     public static function setUpBeforeClass() : void
  6.     {
  7.         require_once 'anagram.php';
  8.     }
  9.  
  10.     public function testNoMatches() : void
  11.     {
  12.         $this->assertEquals([], detectAnagrams('diaper', ['hello', 'world', 'zombies', 'pants']));
  13.     }
  14.  
  15.     public function testDetectsSimpleAnagram() : void
  16.     {
  17.         $this->assertEquals(['tan'], detectAnagrams('ant', ['tan', 'stand', 'at']));
  18.     }
  19.  
  20.     public function testDoesNotDetectFalsePositives() : void
  21.     {
  22.         $this->assertEquals([], detectAnagrams('galea', ['eagle']));
  23.     }
  24.  
  25.     public function testDetectsMultipleAnagrams() : void
  26.     {
  27.         $this->assertEquals(['stream', 'maters'], detectAnagrams('master', ['stream', 'pigeon', 'maters']));
  28.     }
  29.  
  30.     public function testDoesNotDetectAnagramSubsets() : void
  31.     {
  32.         $this->assertEquals([], detectAnagrams('good', ['dog', 'goody']));
  33.     }
  34.  
  35.     public function testDetectsAnagram() : void
  36.     {
  37.         $this->assertEquals(['inlets'], detectAnagrams('listen', ['enlists', 'google', 'inlets', 'banana']));
  38.     }
  39.  
  40.     public function testDetectsMultipleAnagrams2() : void
  41.     {
  42.         $this->assertEquals(
  43.             ['gallery', 'regally', 'largely'],
  44.             detectAnagrams('allergy', ['gallery', 'ballerina', 'regally', 'clergy', 'largely', 'leading'])
  45.         );
  46.     }
  47.  
  48.     public function testDoesNotDetectIdenticalWords() : void
  49.     {
  50.         $this->assertEquals(['cron'], detectAnagrams('corn', ['corn', 'dark', 'Corn', 'rank', 'CORN', 'cron', 'park']));
  51.     }
  52.  
  53.     public function testDoesNotDetectNonAnagramsWithIdenticalChecksum() : void
  54.     {
  55.         $this->assertEquals([], detectAnagrams('mass', ['last']));
  56.     }
  57.  
  58.     public function testDetectsAnagramsCaseInsensitively() : void
  59.     {
  60.         $this->assertEquals(['Carthorse'], detectAnagrams('Orchestra', ['cashregister', 'Carthorse', 'radishes']));
  61.     }
  62.  
  63.     public function testDetectsAnagramsUsingCaseInsensitiveSubject() : void
  64.     {
  65.         $this->assertEquals(['carthorse'], detectAnagrams('Orchestra', ['cashregister', 'carthorse', 'radishes']));
  66.     }
  67.  
  68.     public function testDetectsAnagramsUsingCaseInsensitvePossibleMatches() : void
  69.     {
  70.         $this->assertEquals(['Carthorse'], detectAnagrams('orchestra', ['cashregister', 'Carthorse', 'radishes']));
  71.     }
  72.  
  73.     public function testDoesNotDetectAWordAsItsOwnAnagram() : void
  74.     {
  75.         $this->assertEquals([], detectAnagrams('banana', ['Banana']));
  76.     }
  77.  
  78.     public function testDoesNotDetectAAnagramIfTheOriginalWordIsRepeated() : void
  79.     {
  80.         $this->assertEquals([], detectAnagrams('go', ['go Go GO']));
  81.     }
  82.  
  83.     public function testAnagramsMustUseAllLettersExactlyOnce() : void
  84.     {
  85.         $this->assertEquals([], detectAnagrams('tapper', ['patter']));
  86.     }
  87.  
  88.     public function testEliminatesAnagramsWithTheSameChecksum() : void
  89.     {
  90.         $this->assertEquals([], detectAnagrams('mass', ['last']));
  91.     }
  92.  
  93.     public function testDetectsUnicodeAnagrams() : void
  94.     {
  95.         $this->markTestSkipped('This requires `mbstring` to be installed and thus is optional.');
  96.         $this->assertEquals(['ΒΓΑ', 'γβα'], detectAnagrams('ΑΒΓ', ['ΒΓΑ', 'ΒΓΔ', 'γβα']));
  97.     }
  98.  
  99.     public function testEliminatesMisleadingUnicodeAnagrams() : void
  100.     {
  101.         $this->markTestSkipped('This requires `mbstring` to be installed and thus is optional.');
  102.         $this->assertEquals([], detectAnagrams('ΑΒΓ', ['ABΓ']));
  103.     }
  104.  
  105.     public function testCapitalWordIsNotOwnAnagram() : void
  106.     {
  107.         $this->assertEquals([], detectAnagrams('BANANA', ['Banana']));
  108.     }
  109.  
  110.     public function testAnagramsMustUseAllLettersExactlyOnce2() : void
  111.     {
  112.         $this->assertEquals([], detectAnagrams('patter', ['tapper']));
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement