Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / test / phpUnit / src / unit / StatisticalValuesTest.php @ c3fb3bba

History | View | Annotate | Download (2.33 KB)

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){
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
    return $stat_vals;
33
  }
34

    
35
  function html2text($html){
36
    return  html_entity_decode(strip_tags($html), ENT_COMPAT, 'utf-8');
37
  }
38

    
39
  function test_statistical_values() {
40

    
41
    $stat_vals = $this->create_statistical_values(0.123457,  0.123456, 0.123456523847, 5);
42
    $this->assertEquals('0.123457–0.123456[5;x̄=0.1234565]', $this->html2text(statistical_values($stat_vals)));
43

    
44
    $stat_vals = $this->create_statistical_values(12.23,  14.2, 13.2231423, 15);
45
    $this->assertEquals('12.23–14.2[15;x̄=13.2]', $this->html2text(statistical_values($stat_vals)));
46

    
47
    $stat_vals = $this->create_statistical_values(4,  6, 5, 2);
48
    $this->assertEquals('4–6[2;x̄=5]', $this->html2text(statistical_values($stat_vals)));
49

    
50
    $stat_vals = $this->create_statistical_values(4,  6, 5.0000, 2);
51
    $this->assertEquals('4–6[2;x̄=5]', $this->html2text(statistical_values($stat_vals)));
52

    
53
    $stat_vals = $this->create_statistical_values(6.3467,  6.3482, 6.347034915, 20);
54
    $this->assertEquals('6.3467–6.3482[20;x̄=6.34703]', $this->html2text(statistical_values($stat_vals)));
55

    
56
    $stat_vals = $this->create_statistical_values(0.00000001,  1, (1 - 0.00000001) / 2, 20);
57
    $this->assertEquals('1.0E-8–1[20;x̄=0.5]', $this->html2text(statistical_values($stat_vals)));
58

    
59
  }
60

    
61
}
Add picture from clipboard (Maximum size: 40 MB)