function dividedByThree(int $number): bool { return $number !== 0 && !(bool) base_convert($number, 10, 3)[-1]; }
- function dividedByThree(int $number): bool
- {
while (($number = abs($number)) > 10) {$number = array_sum(str_split($number));}return in_array($number, [3,6,9]);- return $number !== 0 && !(bool) base_convert($number, 10, 3)[-1];
- }
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 testRandomNumbers(){ $random_number_array = range(1, 100); shuffle($random_number_array ); foreach($random_number_array as $value){ $isDivisible = $value % 3 == 0; $this->assertEquals($isDivisible,dividedByThree($value)); } } }
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 testRandomNumbers(){
- $random_number_array = range(1, 100);
- shuffle($random_number_array );
- foreach($random_number_array as $value){
- $isDivisible = $value % 3 == 0;
- $this->assertEquals($isDivisible,dividedByThree($value));
- }
- }
- }