1
|
<?php
|
2
|
|
3
|
// using namespace to allow for better sorting of test classes in the results
|
4
|
namespace test\phpunit\unit;
|
5
|
|
6
|
|
7
|
use PHPUnit\Framework\TestCase;
|
8
|
|
9
|
// these includes require <includePath>../..</includePath> to be set in phpUnit.xml
|
10
|
include 'includes/common.inc';
|
11
|
include 'cdm_api/commons.php';
|
12
|
|
13
|
/**
|
14
|
* test to test if phpUnit is ok
|
15
|
* @author a.kohlbecker
|
16
|
*
|
17
|
*/
|
18
|
class StatisticalValuesTest extends TestCase {
|
19
|
|
20
|
function new_statistical_value($value = null){
|
21
|
$stat_val = new \stdClass(); // need to use the root namespace
|
22
|
$stat_val->_value = $value;
|
23
|
return $stat_val;
|
24
|
}
|
25
|
|
26
|
function create_statistical_values($typicalLowerBoundary = null, $typicalUpperrBoundary = null, $average = null, $sampleSize = null, $variance = null, $standard_deviation = null){
|
27
|
$stat_vals = statistical_values_array();
|
28
|
$stat_vals['TypicalLowerBoundary'] = $this->new_statistical_value($typicalLowerBoundary);
|
29
|
$stat_vals['TypicalUpperBoundary'] = $this->new_statistical_value($typicalUpperrBoundary);
|
30
|
$stat_vals['SampleSize'] = $this->new_statistical_value($sampleSize);
|
31
|
$stat_vals['Average'] = $this->new_statistical_value($average);
|
32
|
if($variance){
|
33
|
$stat_vals['Variance'] = $this->new_statistical_value($variance);
|
34
|
}
|
35
|
if($standard_deviation){
|
36
|
$stat_vals['StandardDeviation'] = $this->new_statistical_value($standard_deviation);
|
37
|
}
|
38
|
return $stat_vals;
|
39
|
}
|
40
|
|
41
|
function html2text($html){
|
42
|
return html_entity_decode(strip_tags($html), ENT_COMPAT, 'utf-8');
|
43
|
}
|
44
|
|
45
|
function test_statistical_values_significant_figures_avarage() {
|
46
|
|
47
|
$stat_vals = $this->create_statistical_values(0.123457, 0.123456, 0.123456523847, 5);
|
48
|
$this->assertEquals('0.123457–0.123456 [5;x̄=0.1234565]', $this->html2text(statistical_values($stat_vals)));
|
49
|
|
50
|
$stat_vals = $this->create_statistical_values(12.23, 14.2, 13.2231423, 15);
|
51
|
$this->assertEquals('12.23–14.2 [15;x̄=13.2]', $this->html2text(statistical_values($stat_vals)));
|
52
|
|
53
|
$stat_vals = $this->create_statistical_values(4, 6, 5, 2);
|
54
|
$this->assertEquals('4–6 [2;x̄=5]', $this->html2text(statistical_values($stat_vals)));
|
55
|
|
56
|
$stat_vals = $this->create_statistical_values(4, 6, 5.0000, 2);
|
57
|
$this->assertEquals('4–6 [2;x̄=5]', $this->html2text(statistical_values($stat_vals)));
|
58
|
|
59
|
$stat_vals = $this->create_statistical_values(6.3467, 6.3482, 6.347034915, 20);
|
60
|
$this->assertEquals('6.3467–6.3482 [20;x̄=6.34703]', $this->html2text(statistical_values($stat_vals)));
|
61
|
|
62
|
$stat_vals = $this->create_statistical_values(0.00000001, 1, (1 - 0.00000001) / 2, 20);
|
63
|
$this->assertEquals('1.0E-8–1 [20;x̄=0.5]', $this->html2text(statistical_values($stat_vals)));
|
64
|
|
65
|
$stat_vals = $this->create_statistical_values(22, 23, 22.5, 4);
|
66
|
$this->assertEquals('22–23 [4;x̄=22.5]', $this->html2text(statistical_values($stat_vals)));
|
67
|
|
68
|
// see https://dev.e-taxonomy.eu/redmine/issues/8771#note-17
|
69
|
$stat_vals = $this->create_statistical_values(22, 23, 22.047619, 24);
|
70
|
$this->assertEquals('22–23 [24;x̄=22]', $this->html2text(statistical_values($stat_vals)));
|
71
|
}
|
72
|
|
73
|
|
74
|
function test_statistical_values_no_min_max() {
|
75
|
|
76
|
$stat_vals = $this->create_statistical_values(null, null, 0.1234, 5);
|
77
|
$this->assertEquals('0.1234 [5]', $this->html2text(statistical_values($stat_vals)));
|
78
|
|
79
|
// as discussed in https://dev.e-taxonomy.eu/redmine/issues/8771#note-16 variance etc should not be suppressed
|
80
|
$stat_vals = $this->create_statistical_values(null, null, 0.1234, 5, 0.3, 0.12);
|
81
|
$this->assertEquals('0.1234 [5;σ²=0.3;σ=0.12]', $this->html2text(statistical_values($stat_vals)));
|
82
|
}
|
83
|
|
84
|
function test_statistical_values_with_unit() {
|
85
|
|
86
|
$stat_vals = $this->create_statistical_values(2.2, 8.7, 5.234, 5, 0.3, 0.12);
|
87
|
$this->assertEquals('2.2–8.7 [5;x̄=5;σ²=0.3;σ=0.12] cm', $this->html2text(statistical_values($stat_vals, 'cm')));
|
88
|
}
|
89
|
|
90
|
|
91
|
function test_statistical_values_no_brackets() {
|
92
|
|
93
|
$stat_vals = $this->create_statistical_values(2.2, 8.7);
|
94
|
$this->assertEquals('2.2–8.7 cm', $this->html2text(statistical_values($stat_vals, 'cm')));
|
95
|
|
96
|
$stat_vals = $this->create_statistical_values(null, null, 5.3);
|
97
|
$this->assertEquals('5.3 m', $this->html2text(statistical_values($stat_vals, 'm')));
|
98
|
}
|
99
|
|
100
|
}
|