mirror of
https://github.com/Respect/Validation.git
synced 2024-06-30 17:50:12 +02:00
PerfectSquare rule check if the sqrt is an integer
This commit is contained in:
parent
b98595a5c0
commit
e4622df22c
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue