@@ -76,6 +76,18 @@ public function __invoke(): void
7676 if ($ c !== '0 ' ) {
7777 $ this ->test ("$ a POW $ b MOD $ c " , fn (Calculator $ calc ) => $ calc ->modPow ($ a , $ b , $ c ));
7878 }
79+
80+ foreach ([$ a , $ b ] as $ n ) {
81+ $ this ->test ("SQRT $ n " , fn (Calculator $ c ) => $ c ->sqrt ($ n ));
82+
83+ for ($ exp = 0 ; $ exp <= 3 ; $ exp ++) {
84+ $ this ->test ("$ n POW $ exp " , fn (Calculator $ calc ) => $ calc ->pow ($ n , $ exp ));
85+
86+ if ($ n !== '0 ' ) {
87+ $ this ->test ("- $ n POW $ exp " , fn (Calculator $ calc ) => $ calc ->pow ("- $ n " , $ exp ));
88+ }
89+ }
90+ }
7991 }
8092 }
8193
@@ -99,10 +111,7 @@ private function runTests(string $a, string $b): void
99111 }
100112
101113 $ this ->test ("GCD $ a, $ b " , fn (Calculator $ c ) => $ c ->gcd ($ a , $ b ));
102-
103- if ($ a [0 ] !== '- ' ) {
104- $ this ->test ("SQRT $ a " , fn (Calculator $ c ) => $ c ->sqrt ($ a ));
105- }
114+ $ this ->test ("LCM $ a, $ b " , fn (Calculator $ c ) => $ c ->lcm ($ a , $ b ));
106115
107116 $ this ->test ("$ a AND $ b " , fn (Calculator $ c ) => $ c ->and ($ a , $ b ));
108117 $ this ->test ("$ a OR $ b " , fn (Calculator $ c ) => $ c ->or ($ a , $ b ));
@@ -120,11 +129,11 @@ private function test(string $test, Closure $callback): void
120129 $ nativeResult = $ callback ($ this ->native );
121130
122131 if ($ gmpResult !== $ bcmathResult ) {
123- $ this ->failure ('GMP ' , 'BCMath ' , $ test );
132+ $ this ->failure ('GMP ' , 'BCMath ' , $ test, $ gmpResult , $ bcmathResult );
124133 }
125134
126135 if ($ gmpResult !== $ nativeResult ) {
127- $ this ->failure ('GMP ' , 'Native ' , $ test );
136+ $ this ->failure ('GMP ' , 'Native ' , $ test, $ gmpResult , $ nativeResult );
128137 }
129138
130139 $ this ->testCounter ++;
@@ -149,12 +158,15 @@ private function test(string $test, Closure $callback): void
149158 * @param string $c1 The name of the first calculator.
150159 * @param string $c2 The name of the second calculator.
151160 * @param string $test A string representing the test being executed.
161+ * @param string $v1 The value returned by the first calculator.
162+ * @param string $v2 The value returned by the second calculator.
152163 */
153- private function failure (string $ c1 , string $ c2 , string $ test ): never
164+ private function failure (string $ c1 , string $ c2 , string $ test, string $ v1 , string $ v2 ): never
154165 {
155166 echo PHP_EOL ;
156167 echo 'FAILURE! ' , PHP_EOL ;
157168 echo $ c1 , ' vs ' , $ c2 , PHP_EOL ;
169+ echo "$ v1 != $ v2 " , PHP_EOL ;
158170 echo $ test , PHP_EOL ;
159171 exit (1 );
160172 }
0 commit comments