$value) { if (!isset($parent[$key]) || $parent[$key] !== $value) { $isSubset = false; break; } } self::assertTrue($isSubset); $arr = [2]; $isSubset = true; $parent = Integer::trialFactorization(2); foreach ($arr as $key => $value) { if (!isset($parent[$key]) || $parent[$key] !== $value) { $isSubset = false; break; } } self::assertTrue($isSubset); self::assertEquals([], Integer::trialFactorization(1)); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox("The Pollard's Roh algorithm calculates a factor of an integer")] public function testPollardsRho() : void { self::assertEquals(101, Integer::pollardsRho(10403, 2, 1, 2, 2)); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('The Fermat factorization calculates a factor of an integer')] public function testFermatFactor() : void { self::assertEquals([59, 101], Integer::fermatFactor(5959)); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('A even number for the fermat factorization throws a InvalidArgumentException')] public function testInvalidFermatParameter() : void { $this->expectException(\InvalidArgumentException::class); Integer::fermatFactor(8); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('The greatest common divisor can be calculated')] public function testGCD() : void { self::assertEquals(4, Integer::greatestCommonDivisor(4, 4)); self::assertEquals(6, Integer::greatestCommonDivisor(54, 24)); self::assertEquals(6, Integer::greatestCommonDivisor(24, 54)); self::assertEquals(1, Integer::greatestCommonDivisor(7, 13)); } }