Created
February 28, 2019 14:41
-
-
Save marttosc/66fbe304e18bdf7b2efc3e863418a9dd to your computer and use it in GitHub Desktop.
Fizz Buzz Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FizzBuzz | |
{ | |
private $number; | |
public function __construct($number) | |
{ | |
$this->number = $number; | |
} | |
public function getResult() | |
{ | |
if ($this->number % 3 == 0 && $this->number % 5 == 0) return 'Fizz Buzz'; | |
if ($this->number % 3 == 0) return 'Fizz'; | |
if ($this->number % 5 == 0) return 'Buzz'; | |
return $this->number; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FizzBuzz | |
{ | |
public function getResult($number) | |
{ | |
if ($number % 3 == 0 && $number % 5 == 0) return 'Fizz Buzz'; | |
if ($number % 3 == 0) return 'Fizz'; | |
if ($number % 5 == 0) return 'Buzz'; | |
return $number; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// require('vendor/autoload.php'); | |
require_once 'FizzBuzzMethod.php'; | |
class FizzBuzzTest extends PHPUnit\Framework\TestCase | |
{ | |
public function testNumber1() | |
{ | |
$fizzbuzz = new FizzBuzz(); | |
$this->assertEquals(1, $fizzbuz->getResult(1)); | |
} | |
public function testNumber2() | |
{ | |
$fizzbuzz = new FizzBuzz(); | |
$this->assertEquals(2, $fizzbuz->getResult(2)); | |
} | |
public function testNumber3() | |
{ | |
$fizzbuzz = new FizzBuzz(); | |
$this->assertEquals('Fizz', $fizzbuz->getResult(3)); | |
} | |
public function testNumber5() | |
{ | |
$fizzbuzz = new FizzBuzz(); | |
$this->assertEquals('Buzz', $fizzbuz->getResult(5)); | |
} | |
public function testNumber6() | |
{ | |
$fizzbuzz = new FizzBuzz(); | |
$this->assertEquals('Fizz', $fizzbuz->getResult(6)); | |
} | |
public function testNumber15() | |
{ | |
$fizzbuzz = new FizzBuzz(); | |
$this->assertEquals('Fizz Buzz', $fizzbuz->getResult(15)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment