My attempts at exercism.org
0
fork

Configure Feed

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

at main 140 lines 4.0 kB view raw
1<?php 2 3use PHPUnit\Framework\TestCase; 4use PHPUnit\Framework\Attributes\TestDox; 5 6class LanguageListTest extends TestCase 7{ 8 public static function setUpBeforeClass(): void 9 { 10 require_once 'LanguageList.php'; 11 } 12 13 /** 14 * @task_id 1 15 */ 16 #[TestDox('calling language_list without arguments, returns empty array')] 17 public function testEmpty() 18 { 19 $language_list = language_list(); 20 $this->assertEquals([], $language_list); 21 } 22 23 /** 24 * @task_id 2 25 */ 26 #[TestDox('variadic call to language_list with 1 arg returns args')] 27 public function testVariadicCallWithOne() 28 { 29 $language_list = language_list('c'); 30 $this->assertEquals(['c'], $language_list); 31 } 32 33 /** 34 * @task_id 2 35 */ 36 #[TestDox('variadic call to language_list with 2 arg returns args')] 37 public function testVariadicCallWithTwo() 38 { 39 $language_list = language_list('c', 'cpp'); 40 $this->assertEquals(['c', 'cpp'], $language_list); 41 } 42 43 /** 44 * @task_id 2 45 */ 46 #[TestDox('variadic call to language_list with 2 arg returns args')] 47 public function testVariadicCallWithThree() 48 { 49 $language_list = language_list('c', 'cpp', 'php'); 50 $this->assertEquals(['c', 'cpp', 'php'], $language_list); 51 } 52 53 /** 54 * @task_id 3 55 */ 56 #[TestDox('push new languages to the back of the list')] 57 public function testAddingToLanguageList() 58 { 59 $language_list = language_list('c', 'cpp', 'php'); 60 $pushed_list = add_to_language_list($language_list, 'java'); 61 $this->assertEquals(['c', 'cpp', 'php', 'java'], $pushed_list); 62 } 63 64 /** 65 * @task_id 3 66 */ 67 #[TestDox('when pushing, original is unchanged')] 68 public function testAddingDoesNotMutate() 69 { 70 $language_list = language_list('c', 'cpp', 'php'); 71 $pushed_list = add_to_language_list($language_list, 'java'); 72 $this->assertNotEquals($language_list, $pushed_list); 73 } 74 75 /** 76 * @task_id 4 77 */ 78 #[TestDox('remove completed language from the front of the list')] 79 public function testCompleteLanguageList() 80 { 81 $language_list = language_list('c', 'cpp', 'php'); 82 $pruned_list = prune_language_list($language_list); 83 $this->assertEquals(['cpp', 'php'], $pruned_list); 84 } 85 86 /** 87 * @task_id 4 88 */ 89 #[TestDox('when pushing, original is unchanged')] 90 public function testPruningDoesNotMutate() 91 { 92 $language_list = language_list('c', 'cpp', 'php'); 93 $pruned_list = prune_language_list($language_list); 94 $this->assertNotEquals($language_list, $pruned_list); 95 } 96 97 /** 98 * @task_id 5 99 */ 100 #[TestDox('index and return the first language')] 101 public function testCurrentReturnsTheFirstLanguage() 102 { 103 $language_list = language_list('php'); 104 $current = current_language($language_list); 105 $this->assertEquals('php', $current); 106 } 107 108 /** 109 * @task_id 5 110 */ 111 #[TestDox('when getting the first language, original is unchanged')] 112 public function testGettingFirstDoesNotMutate() 113 { 114 $language_list = language_list('c', 'cpp', 'php'); 115 current_language($language_list); 116 $this->assertEquals(['c', 'cpp', 'php'], $language_list); 117 } 118 119 /** 120 * @task_id 6 121 */ 122 #[TestDox('the count of the languages in the language list')] 123 public function testLanguageListCount() 124 { 125 $language_list = language_list('c', 'cpp', 'php'); 126 $languages_count = language_list_length($language_list); 127 $this->assertEquals(3, $languages_count); 128 } 129 130 /** 131 * @task_id 6 132 */ 133 #[TestDox('when getting the language count, original is unchanged')] 134 public function testLanguageListCountDoesNotMutate() 135 { 136 $language_list = language_list('c', 'cpp', 'php'); 137 language_list_length($language_list); 138 $this->assertCount(3, $language_list); 139 } 140}