-
-
Save iporsut/8077551 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { | |
function toString($number) { | |
$fizz[true] = "Fizz"; | |
$buzz[true] = "Buzz"; | |
$stillNumber[true] = $number;. | |
$fizz[false] = $buzz[false] = $stillNumber[false] = ''; | |
$result = '';. | |
$result .= $fizz[$number % 3 == 0];. | |
$result .= $buzz[$number % 5 == 0];. | |
$result .= $stillNumber[$number % 3 != 0 && $number % 5 != 0];. | |
return $result; | |
} | |
} |
This file contains hidden or 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_once 'FizzBuzz.php'; | |
class FizzBuzzTest extends \PHPUnit_Framework_TestCase { | |
private $fizzbuzz; | |
function setUp() { | |
$this->fizzbuzz = new FizzBuzz(); | |
} | |
function testFizz() { | |
$result = $this->fizzbuzz->toString(3); | |
$this->assertEquals('Fizz', $result); | |
} | |
function testBuzz() { | |
$result = $this->fizzbuzz->toString(5); | |
$this->assertEquals('Buzz', $result); | |
} | |
function testFizzBuzz() { | |
$result = $this->fizzbuzz->toString(15); | |
$this->assertEquals('FizzBuzz', $result); | |
} | |
function testAnother() { | |
$result = $this->fizzbuzz->toString(1); | |
$this->assertEquals('1', $result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment