-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
64 lines (62 loc) · 2.21 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
function test_clean($input){
return "<<<'TESTING'\n" . $input . "\nTESTING\n";
}
function test($function_name, $desired_output, $function_input){
/*
echo json_encode($function_input, JSON_PRETTY_PRINT)."\n";
echo sizeof($function_input)."\n";
*/
if (gettype(json_decode($function_input)) !== 'array'){
$function_call = 'return '.$function_name."( ".test_clean($function_input)." );";
} else {
$function_input = json_decode($function_input);
$nr_inputs = sizeof($function_input);
if ($nr_inputs < 1)
$function_call = 'return '.$function_name.'();';
else {
$function_call = 'return '.$function_name.'(';
$counter = 1;
foreach ($function_input as $input){
$function_call = $function_call . test_clean($input);
if($counter++ != $nr_inputs)
$function_call = $function_call . ",";
}
$function_call = $function_call .");\n";
}
}
/*echo "<pre>".$function_call."</pre>\n";*/
$function_output = eval($function_call);
/*
$desired_output_ = call_user_func_array
($function_name, $function_input);
*/
test_echo($desired_output, $function_output, $function_input, $function_name);
}
function test_echo($desired_output, $function_output, $function_input, $function_name){
/*echo gettype($function_input);*/
if (gettype($function_input) !== 'array' &&
gettype(json_decode($function_input)) === 'array')
$function_input = json_decode($function_input);
$desired_output_ = ($desired_output == null)
? '`null`' : $desired_output;
$function_output_ = ($function_output == null)
? '`null`' : $function_output;
/*$function_input_ = (sizeof($function_input) < 1)
? '`empty`' : $function_input[0];*/
// finished debug variables cleaning
echo '<pre>';
if(gettype($function_input)==='array')
$function_input = json_encode($function_input, JSON_PRETTY_PRINT);
if($function_output === $desired_output) {
echo "<b><font color=\"LimeGreen\">[O]</font> Passed:</b> 	".$function_name.
"\n| obtained: 	 ".$desired_output_.
"\n| input: 	 ".$function_input;
} else {
echo "<b><font color=\"Red\">[X]</font> Failed:</b> 	".$function_name.
"\n| wanted: 	 ".$desired_output_.
"\n| obtained : 	 ".$function_output_.
"\n| input: 	 ".$function_input;
}
echo "\n\n</pre>";
}