Last active
August 3, 2016 14:09
-
-
Save roongr2k7/8070251 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) { | |
$modThreeIsZero = $number % 3 == 0; | |
$modFiveIsZero = $number % 5 == 0; | |
$fizzWhen = ['', 'Fizz']; | |
$numberUnless = [$number, '']; | |
$buzzWhen = [$numberUnless[$modThreeIsZero], 'Buzz']; | |
return $fizzWhen[$modThreeIsZero] . $buzzWhen[$modFiveIsZero]; | |
} | |
} |
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); | |
} | |
} |
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
@['Fizz'][$n % 3] . [@[$n][$n % 3 == 0], 'Buzz'][$n % 5 == 0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clever!