Project

General

Profile

Download (3.53 KB) Statistics
| Branch: | Tag: | Revision:
1 fa718a2c Andreas Kohlbecker
<?php
2 7c808239 Andreas Kohlbecker
3
// using namespace to allow for better sorting of test classes in the results
4
namespace test\phpunit\unit;
5
6
7 fa718a2c Andreas Kohlbecker
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 458948d0 Andreas Kohlbecker
class StatisticalValuesTest extends TestCase {
19 fa718a2c Andreas Kohlbecker
20
  function new_statistical_value($value = null){
21 7c808239 Andreas Kohlbecker
    $stat_val = new \stdClass(); // need to use the root namespace
22 fa718a2c Andreas Kohlbecker
    $stat_val->_value = $value;
23
    return $stat_val;
24
  }
25
26 dd80884c Andreas Kohlbecker
  function create_statistical_values($typicalLowerBoundary = null, $typicalUpperrBoundary = null, $average  = null, $sampleSize = null, $variance = null, $standard_deviation = null){
27 fa718a2c Andreas Kohlbecker
    $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 dd80884c Andreas Kohlbecker
    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 fa718a2c Andreas Kohlbecker
    return $stat_vals;
39
  }
40
41
  function html2text($html){
42
    return  html_entity_decode(strip_tags($html), ENT_COMPAT, 'utf-8');
43
  }
44
45 dd80884c Andreas Kohlbecker
  function test_statistical_values_significant_figures_avarage() {
46 fa718a2c Andreas Kohlbecker
47 dd80884c Andreas Kohlbecker
    $stat_vals = $this->create_statistical_values(0.123457,  0.123456, 0.1234565345, 5);
48 fa718a2c Andreas Kohlbecker
    $this->assertEquals('0.123457–0.123456[5;x̄=0.1234565]', $this->html2text(statistical_values($stat_vals)));
49 c3fb3bba Andreas Kohlbecker
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 dd80884c Andreas Kohlbecker
    $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 fa718a2c Andreas Kohlbecker
  }
83
84
}