Skip to content

Instantly share code, notes, and snippets.

@samdark
Created November 26, 2011 18:36
Show Gist options
  • Save samdark/1396113 to your computer and use it in GitHub Desktop.
Save samdark/1396113 to your computer and use it in GitHub Desktop.
interview street test runner
<?php
/**
* interview street test runner
*
* Test code should be in /test.php.
* Tests should be unpacked under /tests.
*/
$dir=dirname(__FILE__) . "/tests";
$di=new DirectoryIterator($dir);
/** @var $fileinfo DirectoryIterator */
foreach($di as $fileinfo)
{
if($fileinfo->isFile())
{
if(preg_match('~^input(\d+)~', $fileinfo->getFilename(), $matches))
{
$testNumber = $matches[1];
$inFile = $fileinfo->getFilename();
$outFile = $dir.'/output'.str_pad($testNumber, 2, '0').'.txt';
$out=`php test.php<tests/$inFile`;
$expected = file_get_contents($outFile);
echo "Test $testNumber:\t";
if(trim($expected) != trim($out))
{
echo "[FAIL]\n";
echo "Expected:\n";
echo $expected."\n";
echo "Actual:\n";
echo $out."\n";
}
else
{
echo "[PASS]\n";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment