Stuff - mainly geek, a little diabetes, some rant. Possibly all three in the same post. Basically anything I find interesting and/or worth sharing. These are my personal views, unless I've been hacked.
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/>");
}
?>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment