The thought of today, wrote a test of the PHP function code.
Copy CodeThe code is as follows:
/**
* Parameter Array $paramlist description
*
* The first-dimensional index of an array is the parameter name of the function that needs to be tested, and each element of the second dimension is the possible value that the parameter needs to test, and the element value can be an array.
*/
$ParamList = Array ("Param1" = = Array (3,4,3,2,1),
"PARAM2" = = Array (3,2,5),
"PARAM3" = = Array (0,0.5,1,1.5));
Test function
Systestfunction ("Test", $ParamList);
Functions to be tested
function Test ($Param 1, $Param 2, $Param 3)
{
Return $Param 1. "|" . $Param 2. "|" . $Param 3;
}
/**
* Automatic test
*
* @param string $FunctionName function name
* @param array $ParamList parameter list
* @return Array
*/
function Systestfunction ($FunctionName, $ParamList)
{
if (empty ($FunctionName))
{
echo "function name cannot be empty";
return false;
}
if (!is_array (current ($ParamList)))
{
echo "parameter is not a 2-dimensional array";
return false;
}
$TestParamList = Syscombinearray ($ParamList);
echo "Start Test function". $FunctionName. "
";
foreach ($TestParamList as $Key = $TestParamInfo)
{
echo "Start test section". $Key. "Group Parameters:
";
foreach ($TestParamInfo as $ParamKey = $Param)
{
${"Param". $ParamKey} = $Param;
$TempParamList [] = "$Param". $ParamKey;
if (Is_array ($Param))
{
echo "Parameters". $ParamKey. ", type is an array:";
echo "
";
Print_r ($Param);
}
ElseIf (Is_bool ($Param))
{
echo "Parameters". $ParamKey. ", the type is boll:";
if ($Param)
{
echo "true";
}
Else
{
echo "false";
}
}
Else
{
echo "Parameters". $ParamKey. ", type is a string or number:";
Echo $Param;
}
echo "
";
}
$Params = Join (",", $TempParamList);
Unset ($TempParamList);
Eval ("$TestReturnResult =". $FunctionName. "(" . $Params. ");");
if (Is_array ($TestReturnResult))
{
echo "function returns an array:";
Print_r ($TestReturnResult);
}
ElseIf (Is_bool ($TestReturnResult))
{
if ($TestReturnResult)
{
echo "function returns True";
}
Else
{
echo "function returns false";
}
}
Else
{
echo "function returns a number or string:". $TestReturnResult;
}
echo "
";
}
}
/**
* Functions for calculating combinations
*
* @param array $CombinList 2-D arrays to be sorted together
* @return Array after array combination
*/
function Syscombinearray ($CombinList)
{
if (!is_array (current ($CombinList)))
{
echo "parameter is not a 2-dimensional array";
return false;
}
/* calculate C (a,1) * C (b, 1) * ... * value of C (n, 1) * *
$CombineCount = 1;
foreach ($CombinList as $Key = $Value)
{
$CombineCount *= count ($Value);
}
$RepeatTime = $CombineCount;
foreach ($CombinList as $ClassNo = $ParamList)
{
The maximum number of repetitions of elements in a $ParamList that appear vertically after they are split into groups
$RepeatTime = $RepeatTime/count ($ParamList);
$StartPosition = 1;
foreach ($ParamList as $Param)
{
$TempStartPosition = $StartPosition;
$SpaceCount = $CombineCount/count ($ParamList)/$RepeatTime;
for ($J = 1; $J <= $SpaceCount; $J + +)
{
for ($I = 0; $I < $RepeatTime; $I + +)
{
$Result [$TempStartPosition + $I] [$ClassNo] = $Param;
}
$TempStartPosition + = $RepeatTime * COUNT ($ParamList);
}
$StartPosition + = $RepeatTime;
}
}
return $Result;
}
?>
http://www.bkjia.com/PHPjc/825193.html www.bkjia.com true http://www.bkjia.com/PHPjc/825193.html techarticle the thought of today, wrote a test of the PHP function code. Copy the code as follows:? PHP/** * Parameter Array $paramlist Description * * The first-dimensional index of an array is a letter to be tested ...