11<?php
22
3- /*
4- * By adding type hints and enabling strict type checking, code can become
5- * easier to read, self-documenting and reduce the number of potential bugs.
6- * By default, type declarations are non-strict, which means they will attempt
7- * to change the original type to match the type specified by the
8- * type-declaration.
9- *
10- * In other words, if you pass a string to a function requiring a float,
11- * it will attempt to convert the string value to a float.
12- *
13- * To enable strict mode, a single declare directive must be placed at the top
14- * of the file.
15- * This means that the strictness of typing is configured on a per-file basis.
16- * This directive not only affects the type declarations of parameters, but also
17- * a function's return type.
18- *
19- * For more info review the Concept on strict type checking in the PHP track
20- * <link>.
21- *
22- * To disable strict typing, comment out the directive below.
23- */
24-
253declare (strict_types=1 );
264
275class AlphameticsTest extends PHPUnit \Framework \TestCase
286{
29- private Alphametics $ alphametics ;
30-
317 public static function setUpBeforeClass (): void
328 {
339 require_once 'Alphametics.php ' ;
3410 }
3511
36- public function setUp (): void
37- {
38- $ this ->alphametics = new Alphametics ();
39- }
40-
12+ /**
13+ * uuid e0c08b07-9028-4d5f-91e1-d178fead8e1a
14+ * @testdox puzzle with three letters
15+ */
4116 public function testSolveThreeLetterPuzzle (): void
4217 {
43- $ this ->assertEquals (['I ' => 1 , 'B ' => 9 , 'L ' => 0 ], $ this ->alphametics ->solve ('I + BB == ILL ' ));
18+ $ alphametics = new Alphametics ();
19+ $ this ->assertEquals (['I ' => 1 , 'B ' => 9 , 'L ' => 0 ], $ alphametics ->solve ('I + BB == ILL ' ));
4420 }
4521
22+ /**
23+ * uuid a504ee41-cb92-4ec2-9f11-c37e95ab3f25
24+ * @testdox solution must have unique value for each letter
25+ */
4626 public function testSolutionsMustHaveUniqueValuesForLetters (): void
4727 {
48- $ this ->assertEquals (null , $ this ->alphametics ->solve ('A == B ' ));
28+ $ alphametics = new Alphametics ();
29+ $ this ->assertEquals (null , $ alphametics ->solve ('A == B ' ));
4930 }
5031
32+ /**
33+ * uuid 4e3b81d2-be7b-4c5c-9a80-cd72bc6d465a
34+ * @testdox leading zero solution is invalid
35+ */
5136 public function testLeadingZerosAreInvalid (): void
5237 {
53- $ this ->assertEquals (null , $ this ->alphametics ->solve ('ACA + DD == BD ' ));
38+ $ alphametics = new Alphametics ();
39+ $ this ->assertEquals (null , $ alphametics ->solve ('ACA + DD == BD ' ));
5440 }
5541
42+ /**
43+ * uuid 8a3e3168-d1ee-4df7-94c7-b9c54845ac3a
44+ * @testdox puzzle with two digits final carry
45+ */
5646 public function testPuzzleWithTwoDigitsFinalCarry (): void
5747 {
58- $ result = $ this ->alphametics ->solve ('A + A + A + A + A + A + A + A + A + A + A + B == BCC ' );
48+ $ alphametics = new Alphametics ();
49+ $ result = $ alphametics ->solve ('A + A + A + A + A + A + A + A + A + A + A + B == BCC ' );
5950 $ this ->assertEquals (['A ' => 9 , 'B ' => 1 , 'C ' => 0 ], $ result );
6051 }
6152
53+ /**
54+ * uuid a9630645-15bd-48b6-a61e-d85c4021cc09
55+ * @testdox puzzle with four letters
56+ */
6257 public function testPuzzleWithFourLetters (): void
6358 {
64- $ result = $ this ->alphametics ->solve ('AS + A == MOM ' );
59+ $ alphametics = new Alphametics ();
60+ $ result = $ alphametics ->solve ('AS + A == MOM ' );
6561 $ this ->assertEquals (['A ' => 9 , 'S ' => 2 , 'M ' => 1 , 'O ' => 0 ], $ result );
6662 }
6763
64+ /**
65+ * uuid 3d905a86-5a52-4e4e-bf80-8951535791bd
66+ * @testdox puzzle with six letters
67+ */
6868 public function testPuzzleWithSixLetters (): void
6969 {
70- $ result = $ this ->alphametics ->solve ('NO + NO + TOO == LATE ' );
70+ $ alphametics = new Alphametics ();
71+ $ result = $ alphametics ->solve ('NO + NO + TOO == LATE ' );
7172 $ this ->assertEquals (['N ' => 7 , 'O ' => 4 , 'T ' => 9 , 'L ' => 1 , 'A ' => 0 , 'E ' => 2 ], $ result );
7273 }
7374
75+ /**
76+ * uuid 4febca56-e7b7-4789-97b9-530d09ba95f0
77+ * @testdox puzzle with seven letters
78+ */
7479 public function testPuzzleWithSevenLetter (): void
7580 {
76- $ result = $ this ->alphametics ->solve ('HE + SEES + THE == LIGHT ' );
81+ $ alphametics = new Alphametics ();
82+ $ result = $ alphametics ->solve ('HE + SEES + THE == LIGHT ' );
7783 $ this ->assertEquals (['E ' => 4 , 'G ' => 2 , 'H ' => 5 , 'I ' => 0 , 'L ' => 1 , 'S ' => 9 , 'T ' => 7 ], $ result );
7884 }
7985
86+ /**
87+ * uuid 12125a75-7284-4f9a-a5fa-191471e0d44f
88+ * @testdox puzzle with eight letters
89+ */
8090 public function testPuzzleWithEightLetters (): void
8191 {
82- $ result = $ this ->alphametics ->solve ('SEND + MORE == MONEY ' );
92+ $ alphametics = new Alphametics ();
93+ $ result = $ alphametics ->solve ('SEND + MORE == MONEY ' );
8394 $ this ->assertEquals (['S ' => 9 , 'E ' => 5 , 'N ' => 6 , 'D ' => 7 , 'M ' => 1 , 'O ' => 0 , 'R ' => 8 , 'Y ' => 2 ], $ result );
8495 }
8596
97+ /**
98+ * uuid fb05955f-38dc-477a-a0b6-5ef78969fffa
99+ * @testdox puzzle with ten letters
100+ */
86101 public function testPuzzleWithTenLetters (): void
87102 {
88- $ result = $ this ->alphametics ->solve ('AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE ' );
103+ $ alphametics = new Alphametics ();
104+ $ result = $ alphametics ->solve ('AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE ' );
89105 $ this ->assertEquals ([
90106 'A ' => 5 ,
91107 'D ' => 3 ,
@@ -100,8 +116,13 @@ public function testPuzzleWithTenLetters(): void
100116 ], $ result );
101117 }
102118
119+ /**
120+ * uuid 9a101e81-9216-472b-b458-b513a7adacf7
121+ * @testdox puzzle with ten letters and 199 addends
122+ */
103123 public function testPuzzleWithTenLettersAnd199Addends (): void
104124 {
125+ $ alphametics = new Alphametics ();
105126 $ puzzle = 'THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + TALE + THAT + FALSIFIES + ITS ' .
106127 ' + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES + LATE + AFTER + THE + FIRST ' .
107128 ' + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE + HORSES + OF + FIRE ' .
@@ -117,7 +138,7 @@ public function testPuzzleWithTenLettersAnd199Addends(): void
117138 ' + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS + LIFE + SHORTER + AS + STARS + RISE + THE ' .
118139 ' + HORSES + REST + SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR + AFFILIATES + TAILOR + A ' .
119140 ' + ROOFS + FOR + THEIR + SAFE == FORTRESSES ' ;
120- $ result = $ this -> alphametics ->solve ($ puzzle );
141+ $ result = $ alphametics ->solve ($ puzzle );
121142 $ this ->assertEquals ([
122143 'A ' => 1 ,
123144 'E ' => 0 ,
0 commit comments