Monday, 7 November 2011

FizzBuzz in PHP


<?php
include('../EnhanceTestFramework.php');


class FizzBuzz 
{
    public function fizzBuzzMe($value)
    {
if($value % 15 === 0)
return "FizzBuzz";
if($value % 3 === 0)
return "Fizz";
if($value % 5 === 0)
return "Buzz";
return $value;
    }
}


class FizzBuzzFixture extends EnhanceTestFixture
{
    private $target;
    
    public function setUp()
    {
        $this->target = Enhance::getCodeCoverageWrapper('FizzBuzz');
    }
    
    public function fizzBuzzMeWith1Expect1()
    {
        $result = $this->target->fizzBuzzMe(1);


        Assert::areIdentical(1, $result);
    }
    
    public function fizzBuzzMeWith2Expect2()
    {
        $result = $this->target->fizzBuzzMe(2);


        Assert::areIdentical(2, $result);
    }
    
    public function fizzBuzzMeWith3ExpectFizz()
    {
        $result = $this->target->fizzBuzzMe(3);


        Assert::areIdentical("Fizz", $result);
    }
    
    public function fizzBuzzMeWith5ExpectBuzz()
    {
        $result = $this->target->fizzBuzzMe(5);


        Assert::areIdentical("Buzz", $result);
    }
    
    public function fizzBuzzMeWith15ExpectFizzBuzz()
    {
        $result = $this->target->fizzBuzzMe(15);


        Assert::areIdentical("FizzBuzz", $result);
    }
}


Enhance::runTests();


$y = new FizzBuzz();
for($x = 1; $x <= 100; $x++)
{
echo $y->fizzBuzzMe($x);
echo("<br/>");
}
?>

No comments:

Post a Comment