diff --git a/php/tests/ExampleTest.php b/php/tests/ExampleTest.php deleted file mode 100644 index 5d0a193..0000000 --- a/php/tests/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -<?php - -it('should return true', function () { - expect(false)->toBeTrue(); -}); diff --git a/php/tests/FizzBuzzTest.php b/php/tests/FizzBuzzTest.php new file mode 100644 index 0000000..62e4330 --- /dev/null +++ b/php/tests/FizzBuzzTest.php @@ -0,0 +1,40 @@ +<?php + +// A number is fizz if it is divisible by 3 or if it has a 3 in it +// A number is buzz if it is divisible by 5 or if it has a 5 in it + +function FizzBuzz(int $input) { + $output = ''; + + if ($input % 3 === 0 || stripos($input, '3') !== false) { + $output .= 'Fizz'; + } + + if ($input % 5 === 0 || stripos($input, '5') !== false) { + $output .= 'Buzz'; + } + + return $output ?: (string) $input; +} + +it('should return the input if not divisible by 3 or 5', function ($input, $expected) { + expect(FizzBuzz($input))->toBe($expected); +})->with([ + [1, '1'], + [2, '2'], + [4, '4'], + [7, '7'], + [8, '8'], +]); + +test('Numbers divisible by or containing 3 should return "Fizz"', function ($input) { + expect(FizzBuzz($input))->toBe('Fizz'); +})->with([3, 6, 9, 13]); + +test('Numbers divisible by or containing 5 should return "Buzz"', function ($input) { + expect(FizzBuzz($input))->toBe('Buzz'); +})->with([5, 10, 20, 52]); + +test('Numbers divisible by or containing 5 or divisible or containing 3 should return "FizzBuzz"', function ($input) { + expect(FizzBuzz($input))->toBe('FizzBuzz'); +})->with([15, 30, 35, 53]); \ No newline at end of file