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.
Tuesday, 8 November 2011
FizzBuzz in Ruby
def fizzBuzzMe(input)
if input % 15 == 0
'FizzBuzz'
elsif input % 5 == 0
'Buzz'
elsif input % 3 == 0
'Fizz'
else
input
end
end
#tests
#puts fizzBuzzMe(1)
#puts fizzBuzzMe(2)
#puts fizzBuzzMe(3)
#puts fizzBuzzMe(5)
#puts fizzBuzzMe(15)
for i in (1..100)
puts fizzBuzzMe(i)
end
gets
Labels:
Ruby
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/>");
}
?>
Labels:
PHP
Subscribe to:
Posts (Atom)