PerfectSquare rule check if the sqrt is an integer

This commit is contained in:
Felipe Martins 2015-11-06 01:19:40 -02:00 committed by Henrique Moody
parent b98595a5c0
commit e4622df22c
2 changed files with 3 additions and 2 deletions

View file

@ -5,6 +5,6 @@ class PerfectSquare extends AbstractRule
{
public function validate($input)
{
return is_numeric($input) && sqrt($input) * sqrt($input) == $input;
return is_numeric($input) && floor(sqrt($input)) == sqrt($input);
}
}

View file

@ -45,13 +45,14 @@ class PerfectSquareTest extends \PHPUnit_Framework_TestCase
array('0'),
array(81),
array(0),
array(250),
array(2500),
);
}
public function providerForNotPerfectSquare()
{
return array(
array(250),
array(null),
array(7),
array(-1),