Created
December 17, 2012 11:52
-
-
Save haru01/4317709 to your computer and use it in GitHub Desktop.
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 converts($numbers) | |
{ | |
$self = $this; | |
return __::map($numbers, function($n) use($self) { | |
return $self->convert($n); | |
}); | |
} | |
public function convert($num) | |
{ | |
if ($num % 15 == 0) { | |
return "FIZZBUZZ"; | |
} | |
if ($num % 3 == 0) { | |
return "FIZZ"; | |
} | |
if ($num % 5 == 0) { | |
return "BUZZ"; | |
} | |
return $num; | |
} | |
} | |
class FizzBuzzTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testFIZZBUZZ配列を返すこと() | |
{ | |
$target = new FizzBuzz(); | |
$expected = array(1, 2, "FIZZ", 4 , "BUZZ", "FIZZ", 7, 8, "FIZZ", "BUZZ", 11, "FIZZ", 13, 14, "FIZZBUZZ"); | |
$this->assertEquals($expected, $target->converts(range(1, 15))); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment