function dividedByThree(int $number): bool { return (3 == $number = abs($number)) ? true : (($number < 6) ? false : in_array($number, range(3, $number, 3))); }
- function dividedByThree(int $number): bool
- {
$i = 3;do {if (abs($number) === $i) {return true;}$i += 3;} while (abs($number) >= $i);return false;- return (3 == $number = abs($number)) ? true : (($number < 6) ? false : in_array($number, range(3, $number, 3)));
- }
class MyTestCasesTest 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)); } public function testRandom() { $r = []; for($i = 2000; $i > 0; $i--){ $r[] = rand(-99999, 99999) * 3; } foreach($r as $r){ $this->assertTrue(dividedByThree($r)); $this->assertFalse(dividedByThree($r + 1)); $this->assertFalse(dividedByThree($r + 2)); } } }
class MyTestCases extends TestCase- class MyTestCasesTest 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));
- }
- public function testRandom() {
- $r = [];
- for($i = 2000; $i > 0; $i--){
- $r[] = rand(-99999, 99999) * 3;
- }
- foreach($r as $r){
- $this->assertTrue(dividedByThree($r));
- $this->assertFalse(dividedByThree($r + 1));
- $this->assertFalse(dividedByThree($r + 2));
- }
- }
- }