My attempts at exercism.org
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 109 lines 2.9 kB view raw
1<?php 2 3declare(strict_types=1); 4 5use PHPUnit\Framework\TestCase; 6use PHPUnit\Framework\Attributes\TestDox; 7 8class HammingTest extends TestCase 9{ 10 public static function setUpBeforeClass(): void 11 { 12 require_once 'Hamming.php'; 13 } 14 15 /** 16 * uuid: f6dcb64f-03b0-4b60-81b1-3c9dbf47e887 17 */ 18 #[TestDox('Empty strands')] 19 public function testEmptyStrands(): void 20 { 21 $this->assertEquals(0, distance('', '')); 22 } 23 24 /** 25 * uuid: 54681314-eee2-439a-9db0-b0636c656156 26 */ 27 #[TestDox('Single letter identical strands')] 28 public function testSingleLetterIdenticalStrands(): void 29 { 30 $this->assertEquals(0, distance('A', 'A')); 31 } 32 33 /** 34 * uuid: 294479a3-a4c8-478f-8d63-6209815a827b 35 */ 36 #[TestDox('Single letter different strands')] 37 public function testSingleLetterDifferentStrands(): void 38 { 39 $this->assertEquals(1, distance('G', 'T')); 40 } 41 42 /** 43 * uuid: 9aed5f34-5693-4344-9b31-40c692fb5592 44 */ 45 #[TestDox('Long identical strands')] 46 public function testLongIdenticalStrands(): void 47 { 48 $this->assertEquals(0, distance( 49 'GGACTGAAATCTG', 50 'GGACTGAAATCTG' 51 )); 52 } 53 54 /** 55 * uuid: cd2273a5-c576-46c8-a52b-dee251c3e6e5 56 */ 57 #[TestDox('Long different strands')] 58 public function testLongDifferentStrand(): void 59 { 60 $this->assertEquals(9, distance( 61 'GGACGGATTCTG', 62 'AGGACGGATTCT' 63 )); 64 } 65 66 /** 67 * uuid: b9228bb1-465f-4141-b40f-1f99812de5a8 68 */ 69 #[TestDox('Disallow first strand longer')] 70 public function testDisallowFirstStrandLonger(): void 71 { 72 $this->expectException('InvalidArgumentException'); 73 $this->expectExceptionMessage('strands must be of equal length'); 74 distance('AATG', 'AAA'); 75 } 76 77 /** 78 * uuid: dab38838-26bb-4fff-acbe-3b0a9bfeba2d 79 */ 80 #[TestDox(': Disallow second strand longer')] 81 public function testDisallowSecondStrandLonger(): void 82 { 83 $this->expectException('InvalidArgumentException'); 84 $this->expectExceptionMessage('strands must be of equal length'); 85 distance('ATA', 'AATG'); 86 } 87 88 /** 89 * uuid: b764d47c-83ff-4de2-ab10-6cfe4b15c0f3 90 */ 91 #[TestDox(': Disallow empty first strand')] 92 public function testDisallowEmptyFirstStrand(): void 93 { 94 $this->expectException('InvalidArgumentException'); 95 $this->expectExceptionMessage('strands must be of equal length'); 96 distance('', 'G'); 97 } 98 99 /** 100 * uuid: 9ab9262f-3521-4191-81f5-0ed184a5aa89 101 */ 102 #[TestDox(': Disallow empty second strand')] 103 public function testDisallowEmptySecondStrand(): void 104 { 105 $this->expectException('InvalidArgumentException'); 106 $this->expectExceptionMessage('strands must be of equal length'); 107 distance('G', ''); 108 } 109}