mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Add Miscellaneous::calculateGreatestCommonDivisor() method
This commit is contained in:
@@ -735,6 +735,18 @@ class MiscellaneousTest extends BaseTestCase
|
||||
self::assertEquals($expected, Miscellaneous::removeMarginalCharacter($string, $last), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $first
|
||||
* @param int $second
|
||||
* @param int $expected
|
||||
*
|
||||
* @dataProvider provideGreatestCommonDivisor
|
||||
*/
|
||||
public function testCalculateGreatestCommonDivisor(int $first, int $second, int $expected): void
|
||||
{
|
||||
static::assertSame($expected, Miscellaneous::calculateGreatestCommonDivisor($first, $second));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
||||
*
|
||||
@@ -1506,6 +1518,51 @@ class MiscellaneousTest extends BaseTestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function provideGreatestCommonDivisor(): ?Generator
|
||||
{
|
||||
yield[
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
];
|
||||
|
||||
yield[
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
];
|
||||
|
||||
yield[
|
||||
5,
|
||||
3,
|
||||
1,
|
||||
];
|
||||
|
||||
yield[
|
||||
6,
|
||||
3,
|
||||
3,
|
||||
];
|
||||
|
||||
yield[
|
||||
12,
|
||||
9,
|
||||
3,
|
||||
];
|
||||
|
||||
yield[
|
||||
20,
|
||||
12,
|
||||
4,
|
||||
];
|
||||
|
||||
yield[
|
||||
120,
|
||||
80,
|
||||
40,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user