栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > msqphp

测试文件例-数组篇 - msqphp轻量级php7.1框架beta -1.9版本使用手册

msqphp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

测试文件例-数组篇 - msqphp轻量级php7.1框架beta -1.9版本使用手册


###测试文件例-数组篇

namespace msqphptestbasearr;

// 继承测试类
class ArrTest extends msqphptestTest
{
public function testStart() : void
{
// 由于对应的测试类为Arr基类,全部为静态函数,所以在此处赋类值
$this->class('msqphpbasearrArr');
// 测试当前对象
$this->testThis($this);
}
// 测试所有数组排序函数
public function testSort() : void
{
// 清空数据,避免数据混乱造成错误
$this->clear();
// args,此处为待排序数组
$args = [1,2,465,47,136,49,136,49,13,496,31,74,64,46];
// result,此处为结果,即排序后的数组
$result = [1,2,13,31,46,47,49,49,64,74,136,136,465,496];
// 因为参数与结果,所以统一赋值.
$this->args($args)->result($result);
// 分辨测试各个函数
$this->method('bubbleSort')->test();
$this->method('insertSort')->test();
$this->method('quickSort')->test();
$this->method('selectSort')->test();
}
public function testSetAndGet() : void
{
// 清空数据,避免数据混乱造成错误
$this->clear();
// args,此处为数据数组
$args = [
'liming'=>['name'=>'liming','age'=>12],
'wangwu'=>['name'=>'wangwu','age'=>27],
'zhanghai'=>['name'=>'zhanghai','age'=>50],
'changni'=>['name'=>'changni','age'=>34],
];
// 由于该函数为值引用传递,有些bug,所以人工测试
msqphpbasearrArr::set($args, 'changni.age', 57);

// 结果不为57,报错
if ($args['changni']['age'] !== 57 || msqphpbasearrArr::get($args, 'changni.age') !== 57) {
echo '该函数由于值为应用传递,所以采用非正常测试,此时测试失败';
throw new msqphptestTestException('测试失败');
}
echo '该函数由于值为应用传递,所以采用非正常测试,此时测试成功';
}
public function testRandom() : void
{
// 清空数据,避免数据混乱造成错误
$this->clear();
// 数组范围,1-19的单数
$args = [1,3,5,7,9,11,13,15,17,19];
// 方法,参数,结果以函数形式判断true通过,false则失败报错
$this->method('random')->args($args)->result(function (int $value) use ($args) : bool {
return in_array($value, $args);
})->test();

// 测试当数组中取多个值,
$num = random_int(1, 7);

$this->method('random')->args($args, $num)->result(function (array $value) use ($args, $num) : bool {
$bool = true;
$bool = count($value) === $num && $bool;
foreach ($value as $number) {
$bool = $bool && in_array($number, $args);
}
return $bool;
})->test();
}
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/213991.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号