diff --git a/solutions/php/factorial.php b/solutions/php/factorial.php index c2dfc48..2beb022 100644 --- a/solutions/php/factorial.php +++ b/solutions/php/factorial.php @@ -1,35 +1,36 @@ +} diff --git a/tests/php/IntegerLengthTest.php b/tests/php/IntegerLengthTest.php new file mode 100644 index 0000000..f718471 --- /dev/null +++ b/tests/php/IntegerLengthTest.php @@ -0,0 +1,16 @@ +assertEquals(1, IntegerLength(1)); + $this->assertEquals(2, IntegerLength(22)); + $this->assertEquals(3, IntegerLength(333)); + $this->assertEquals(10, IntegerLength(1234567890)); + + } +} diff --git a/tests/php/factorialTest.php b/tests/php/factorialTest.php index 6544c0e..b06e01e 100644 --- a/tests/php/factorialTest.php +++ b/tests/php/factorialTest.php @@ -7,10 +7,31 @@ class FactorialTest extends TestCase { public function test_factorial() { - $this->assertEquals(1, factorial(1)); - $this->assertEquals(2, factorial(2)); - $this->assertEquals(6, factorial(3)); - $this->assertEquals(120, factorial(5)); - $this->assertEquals(2432902008176640000, factorial(20)); + $this->verifyFactorial("factorial"); + } + + public function test_factorialReverse() + { + $this->verifyFactorial("factorialReverse"); + } + + public function test_factorialRecursive() + { + $this->verifyFactorial("factorialRecursive"); + } + + private function verifyFactorial($fn) + { + $testDataMap = [ + ["input" => 1, "expect" => 1], + ["input" => 2, "expect" => 2], + ["input" => 3, "expect" => 6], + ["input" => 5, "expect" => 120], + ["input" => 20, "expect" => 2432902008176640000], + ]; + + foreach ($testDataMap as $data) { + $this->assertEquals($data["expect"], call_user_func($fn, $data["input"])); + } } }