Created
September 19, 2013 19:59
-
-
Save armonge/6629013 to your computer and use it in GitHub Desktop.
Kata #1 (PHP) Webcast Agilityfeat. https://plus.google.com/114642677983172790710/posts/erAyjcXgkLp
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 | |
{ | |
static public function categorize($num) { | |
$result = ''; | |
if($num === 0){ | |
return '0'; | |
} | |
$result .= FizzBuzz::isFizz($num); | |
$result .= FizzBuzz::isBuzz($num); | |
if($result === ''){ | |
$result = (string) $num; | |
} | |
return $result; | |
} | |
static private function isFizz($num){ | |
return $num % 3 === 0 ? 'fizz' : ''; | |
} | |
static private function isBuzz($num){ | |
return $num % 5 === 0 ? 'buzz' : ''; | |
} | |
} |
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 'fizzbuzz.php'; | |
class TestFizzBuzz extends PHPUnit_Framework_TestCase | |
{ | |
public function testCategorizeAsIs(){ | |
$this->assertEquals('0', FizzBuzz::categorize(0)); | |
$this->assertEquals('1', FizzBuzz::categorize(1)); | |
} | |
public function testCategorizeBuzz(){ | |
$this->assertEquals('buzz', FizzBuzz::categorize(5)); | |
$this->assertEquals('buzz', FizzBuzz::categorize(10)); | |
} | |
public function testCategorizeFizz(){ | |
$this->assertEquals('fizz', FizzBuzz::categorize(3)); | |
$this->assertEquals('fizz', FizzBuzz::categorize(6)); | |
} | |
public function testCategorizeFizzBuzz(){ | |
$this->assertEquals('fizzbuzz', FizzBuzz::categorize(30)); | |
$this->assertEquals('fizzbuzz', FizzBuzz::categorize(15)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment