Exemple #1
0
 */
echo "Please enter two odd numbers to find the commond factories, separated by space. For example 12345 8873.\n";
/**
 * Get the command line input
 */
$handle = fopen("php://stdin", "r");
$line = trim(fgets($handle));
$numbers = explode(" ", $line);
/**
 * Check if all the numbers are odd 
 */
checkIsOdd($numbers);
/**
 * initial main object and call the method
 */
$obj = new CommonOddFactor($numbers[0], $numbers[1]);
$ary = $obj->getAllCommonFactors();
/**
 * Echo out the result
 */
echo "The common factories are: \n";
foreach ($ary as $n) {
    echo $n . "\n";
}
/**
 * utility functions: check both numbers
 */
function checkIsOdd($ary)
{
    foreach ($ary as $n) {
        if (!isOdd($n)) {
 /**
  * test common factories
  */
 public function testfactories2()
 {
     $obj = new CommonOddFactor(133, 21);
     $obj->getAllCommonFactors();
     $this->assertEmpty(array_diff($obj->factors, array(1, 7)));
 }