Skip to content

Instantly share code, notes, and snippets.

@haru01
Created December 17, 2012 11:52
Show Gist options
  • Save haru01/4317709 to your computer and use it in GitHub Desktop.
Save haru01/4317709 to your computer and use it in GitHub Desktop.
<?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