Write a function that takes an integer as input, and returns boolean divisibility by 3 for input argument. You can't use /
as operator
Example: The number 3
is divisible by three without leaving a remainder, so the function should return true
in this case
function dividedByThree(int $number): bool
{
$i = 3;
do {
if (abs($number) === $i) {
return true;
}
$i += 3;
} while (abs($number) >= $i);
return false;
}
class MyTestCases extends TestCase
{
public function testDividedByThree() {
$this->assertTrue(dividedByThree(3));
$this->assertTrue(dividedByThree(12));
$this->assertFalse(dividedByThree(13));
$this->assertFalse(dividedByThree(0));
$this->assertTrue(dividedByThree(-12));
}
}