Created
November 26, 2011 18:36
-
-
Save samdark/1396113 to your computer and use it in GitHub Desktop.
interview street test runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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