* Add unit test for metric.

This commit is contained in:
zhouxin
2023-08-03 10:46:47 +08:00
parent 97fc6031b0
commit 7698b97939
3 changed files with 29 additions and 3 deletions
@@ -28,7 +28,7 @@ class count_of_delayed_finished_execution_which_annual_finished extends baseCalc
public function calculate($row)
{
if(empty($row->closedDate) or empty($row->firstEnd)) return false;
if(empty($row->closedDate) || empty($row->firstEnd)) return false;
$year = substr($row->closedDate, 0, 4);
if($year == '0000') return false;
@@ -42,8 +42,7 @@ class count_of_delayed_finished_execution_which_annual_finished extends baseCalc
public function getResult($options = array())
{
$records = array();
foreach($this->result as $year => $value) $records[] = array('year' => $year, 'value' => $value);
$records = $this->getRecords(array('year', 'value'));
return $this->filterByOptions($records, $options);
}
}
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 7) . '/test/lib/init.php';
include dirname(__FILE__, 4) . '/calc.class.php';
zdTable('project')->config('project_close', $useCommon = true, $levels = 4)->gen(10);
zdTable('project')->config('execution', $useCommon = true, $levels = 4)->gen(100, false);
$metric = new metricTest();
$calc = $metric->calcMetric(__FILE__);
/**
title=count_of_delayed_finished_execution_which_annual_finished
timeout=0
cid=1
*/
r(count($calc->getResult())) && p('') && e('2'); // 测试分组数
r($calc->getResult(array('year' => '2011'))) && p('0:value') && e('8'); // 测试2011年完成执行中延期完成执行数
r($calc->getResult(array('year' => '2012'))) && p('0:value') && e('8'); // 测试2012年完成执行中延期完成执行数
+4
View File
@@ -21,4 +21,8 @@ fields:
range: "20110101 000000-20210101 000000:10D"
type: timestamp
format: YYYY-MM-DD
- field: firstEnd
range: "20010101 000000-20110101 000000:10D"
type: timestamp
format: YYYY-MM-DD
...