quote:
I've just been reading that really you shouldn't have more than 1 assertion per test case.
If anyone says explicitly that then they're probably an idiot.
Each test case should* be
a test case, but use however many assertions it takes to test that case.
*It's partly just a benefit of maintainability/comprehension (so personal preference), but also a matter of not having logic in your test cases which could itself contain bugs (that then potentially obscures actual bugs).
If the code you posted was mine, I'd probably simplify the existing functions to this:
php code:
public function testToHexAndBack()
{
$cmy = CMY::create($c, $m, $y)->toHex()->toCMY();
$this->assertEquals($c, $cmy->c, null, self::DELTA);
$this->assertEquals($m, $cmy->m, null, self::DELTA);
$this->assertEquals($y, $cmy->y, null, self::DELTA);
}
And then process them like this:
php code:
function testRoundingStuff()
{
for ($c=0; $c<=1; $c+=0.05)
{
for ($m=0; $m<=1; $m+=0.05)
{
for ($y=0; $y<=1; $y+=0.05)
{
testToHexAndBack($c,$m,$y);
testToRGBAndBack($c,$m,$y);
// etc
}
}
}
}
EDITED: 13 Jun 2012 22:55 by BOUGHTONP