How to test php functions_PHP tutorial

WBOY
Release: 2016-07-13 10:25:13
Original
819 people have browsed it

I suddenly thought of it today and wrote a piece of code to test the php function.

Copy code The code is as follows:

/**
* 参数数组$ParamList说明
*
* 数组的第一维索引是需要测试的函数的参数名,第二维的每个元素是该参数需要测试的可能值,元素值可以为数组。
*/
$ParamList = array("Param1" => array(3,4,3,2,1),
                   "Param2" => array(3,2,5),
                   "Param3" => array(0,0.5,1,1.5));
// 测试函数
sysTestFunction("Test", $ParamList);

// 待测试的函数
function Test($Param1, $Param2, $Param3)
{
    return $Param1 . "|" . $Param2 . "|" . $Param3;
}

/**
* Automatic test
*
* @param string $FunctionName Function name
* @param array $ParamList Parameter list
* @return array
*/
function sysTestFunction($FunctionName, $ParamList)
{
if(empty($FunctionName))
{
echo "The function name cannot be Is empty";
            return false; ;
}
$TestParamList = sysCombineArray($ParamList);
echo "Start test function" . $FunctionName . "
";
foreach($TestParamList as $Key = >
                                                                                                                                                                                                                      ${"Param" . $ParamKey} = $Param; { echo "parameter". $ Paramkey. ", The type is array:";
echo "& lt;";
Print_r ($ param);
}
Elseif (is_Bool ($Param))
{
                              echo "true";
                                                                                                                                                                                                                                                                                                    else String or number: ";
                     echo $Param; empParamList);
unset($TempParamList);
eval("$TestReturnResult = " . $FunctionName . "(" . $Params . ");");
if(is_array($TestReturnResult))
{
                                                                                                        using using using using               use using       through   through out through out through out out through out’s'''' through' ‐ to ‐ ‐‐‐‐‐‐‐ ‐ echo "Function return array:

";                                                                                                            
elseif(is_bool($TestReturnResult))
{
🎜>        }
                                                                                                                          🎜>                                                                                                                                                                                                                                                                 since turnResult;
}
echo "

";
}
}
/**
* Function to calculate combination
*
* @param array $CombinList 2-dimensional array to be arranged and combined
* @return array The combined array
*/
function sysCombineArray($CombinList)
{
if(!is_array(current($CombinList)))
{
echo "The 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 vertical repetitions of the elements in $ParamList after splitting into combinations
                                                                                                                                                                                                             through $ParamList $StartPosition                    $RepeatTime                      $ParamList   Param)
                                                                                                                                                                                                                                       ;                                             SpaceCount ; $J ++)
{
for($I = 0; $I < $RepeatTime; $I ++)
{
$Result[$T empStartPosition + $I][$ ClassNo] = $Param;
                                                                                                                      tTime;
}
}
Return $Result;
}
?>






http://www.bkjia.com/PHPjc/825193.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/825193.html

TechArticle

I suddenly thought of it today and wrote a piece of code to test the php function. Copy the code The code is as follows: ?php /** * Parameter array $ParamList description * * The first dimension index of the array is the function that needs to be tested...

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!