ScrabbleScoreTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Calculate the value of scrabble score for a given word.
  5. */
  6. class ScrabbleScoreTest extends PHPUnit\Framework\TestCase
  7. {
  8. public static function setUpBeforeClass(): void
  9. {
  10. require_once 'ScrabbleScore.php';
  11. }
  12. /**
  13. * uuid f46cda29-1ca5-4ef2-bd45-388a767e3db2
  14. * @testdox Lowercase letter
  15. */
  16. public function testLowercaseSingleLetter(): void
  17. {
  18. $word = 'a';
  19. $this->assertEquals(1, score($word));
  20. }
  21. /**
  22. * uuid f7794b49-f13e-45d1-a933-4e48459b2201
  23. * @testdox Uppercase letter
  24. */
  25. public function testUppercaseSingleLetter(): void
  26. {
  27. $word = 'A';
  28. $this->assertEquals(1, score($word));
  29. }
  30. /**
  31. * uuid eaba9c76-f9fa-49c9-a1b0-d1ba3a5b31fa
  32. * @testdox Valuable letter
  33. */
  34. public function testValuableSingleLetter(): void
  35. {
  36. $word = 'f';
  37. $this->assertEquals(4, score($word));
  38. }
  39. /**
  40. * uuid f3c8c94e-bb48-4da2-b09f-e832e103151e
  41. * @testdox Short word
  42. */
  43. public function testShortWord(): void
  44. {
  45. $word = 'at';
  46. $this->assertEquals(2, score($word));
  47. }
  48. /**
  49. * uuid 71e3d8fa-900d-4548-930e-68e7067c4615
  50. * @testdox Short, valuable word
  51. */
  52. public function testShortValuableWord(): void
  53. {
  54. $word = 'zoo';
  55. $this->assertEquals(12, score($word));
  56. }
  57. /**
  58. * uuid d3088ad9-570c-4b51-8764-c75d5a430e99
  59. * @testdox Medium word
  60. */
  61. public function testMediumWord(): void
  62. {
  63. $word = 'street';
  64. $this->assertEquals(6, score($word));
  65. }
  66. /**
  67. * uuid fa20c572-ad86-400a-8511-64512daac352
  68. * @testdox Medium, valuable word
  69. */
  70. public function testMediumValuableWord(): void
  71. {
  72. $word = 'quirky';
  73. $this->assertEquals(22, score($word));
  74. }
  75. /**
  76. * uuid 9336f0ba-9c2b-4fa0-bd1c-2e2d328cf967
  77. * @testdox Long, mixed-case word
  78. */
  79. public function testLongMixedCaseWord(): void
  80. {
  81. $word = 'OxyphenButazone';
  82. $this->assertEquals(41, score($word));
  83. }
  84. /**
  85. * uuid 1e34e2c3-e444-4ea7-b598-3c2b46fd2c10
  86. * @testdox English-like word
  87. */
  88. public function testEnglishLikeWord(): void
  89. {
  90. $word = 'pinata';
  91. $this->assertEquals(8, score($word));
  92. }
  93. /**
  94. * uuid 4efe3169-b3b6-4334-8bae-ff4ef24a7e4f
  95. * @testdox Empty input
  96. */
  97. public function testEmptyWordScore(): void
  98. {
  99. $word = '';
  100. $this->assertEquals(0, score($word));
  101. }
  102. /*
  103. * uuid 3b305c1c-f260-4e15-a5b5-cb7d3ea7c3d7
  104. * @testdox Entire alphabet available
  105. */
  106. public function testEntireAlphabetWord(): void
  107. {
  108. $word = 'abcdefghijklmnopqrstuvwxyz';
  109. $this->assertEquals(87, score($word));
  110. }
  111. }