Skip to content

Commit

Permalink
Add PHP ver.
Browse files Browse the repository at this point in the history
  • Loading branch information
7kaji committed Dec 16, 2015
1 parent 73d404b commit 33571fb
Show file tree
Hide file tree
Showing 4 changed files with 1,045 additions and 0 deletions.
44 changes: 44 additions & 0 deletions FizzBuzz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env php

<?php
class FizzBuzz
{
function say($n)
{
if($this->fizz_buzz($n)){
return "FizzBuzz";
}
elseif($this->fizz($n)){
return "Fizz";
}
elseif($this->buzz($n)){
return "Buzz";
}
else{
return $n;
}
}

private function fizz_buzz($n)
{
if($this->fizz($n) && $this->buzz($n)){ return true;}else{ return false;}
}

private function fizz($n)
{
if($n % 3 == 0){ return true;}else{ return false;}
($n % 3 == 0) ? true : false;
}

private function buzz($n)
{
if($n % 5 == 0){ return true;}else{ return false;}
}

}

// $numbers = new FizzBuzz();
// for ($i = 1; $i <= 30; $i++)
// {
// echo("{$i}\t:{$numbers->say($i)}\n");
// }
26 changes: 26 additions & 0 deletions FizzBuzzTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

require_once 'FizzBuzz.php';

class FizzBuzzTest extends PHPUnit_Framework_TestCase
{
function setUp(){
$this->number = new FizzBuzz();
}

function test_say(){
$this->assertEquals(1, $this->number->say(1));
}

function test_say3(){
$this->assertEquals('Fizz', $this->number->say(3));
}

function test_say5(){
$this->assertEquals('Buzz', $this->number->say(5));
}

function test_say15(){
$this->assertEquals('FizzBuzz', $this->number->say(15));
}
}
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"phpunit/phpunit": "4.8.*"
}
}
Loading

0 comments on commit 33571fb

Please sign in to comment.