Skip to content

Instantly share code, notes, and snippets.

@israelst
Created November 5, 2011 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save israelst/1341346 to your computer and use it in GitHub Desktop.
Save israelst/1341346 to your computer and use it in GitHub Desktop.
Mini tester
<?php
function test($expected, $obtained){
if($expected != $obtained){
return "Falha, $expected é diferente de $obtained";
}else{
return "Ok";
}
}
function test_runner($test_list){
foreach($test_list as $test_name => $test){
echo $test_name . ": " . $test() . "\n";
}
}
function soma($a, $b){
return $a + $b;
}
$test_list = array(
'Soma deve retornar 2 ao receber 1 e 1' => function(){
return test(2, soma(1, 1));
},
'Soma deve retornar 4 ao receber 2 e 2' => function(){
return test(4, soma(2, 2));
}
);
test_runner($test_list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment