Skip to content

Commit

Permalink
integration tests for math/statistical formats (#608)
Browse files Browse the repository at this point in the history
* improvements of spelling mistakes

* Added integration tests (variance, samplevariance, samplestandarddeviation, standarddeviation, range)

* Added integration tests (quartillower, quartilupper, quartillower.exc, quartilupper.exc, interquartilerange, interquartilerange.exc, interquartilemean, mode)

* Added integration test (should now test all functions)

* Update SRF_Math.php

* corrected integration tests

* corrected integration test (spelling mistake)

* improved order

* removed mode from testing

* removed mode from testing

* added mode back into integration testing

Co-authored-by: Florian Breitenlacher <[email protected]>
  • Loading branch information
Bernhard Krabina and Florian Breitenlacher authored Aug 27, 2020
1 parent 3501bb3 commit a54e8ce
Show file tree
Hide file tree
Showing 2 changed files with 308 additions and 6 deletions.
24 changes: 19 additions & 5 deletions formats/math/SRF_Math.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Various mathematical functions - sum, product, average, min and max.
* Various mathematical functions - sum, product, average, min, max, median, variance, samplevariance, samplestandarddeviation, standarddeviation, range, quartillower, quartilupper, quartillower.exc, quartilupper.exc, interquartilerange, interquartilerange.exc, mode and interquartilemean
*
* @licence GNU GPL v3+
*
Expand Down Expand Up @@ -31,7 +31,7 @@ public static function sum_function(array $numbers)
return array_sum($numbers);
}

public static function pruduct_function(array $numbers)
public static function product_function(array $numbers)
{
// result
return array_product($numbers);
Expand Down Expand Up @@ -110,6 +110,7 @@ public static function samplestandarddeviation_function(array $numbers)

public static function range_function(array $numbers)
{
// result
return (max($numbers) - min($numbers));
}

Expand All @@ -123,10 +124,12 @@ public static function quartillower_inc_function(array $numbers)
{
$Q1_position_y = floor($Q1_position);
$Q1_position_x = ceil($Q1_position);
// result
return ($numbers[$Q1_position_y] + ($numbers[$Q1_position_x] - $numbers[$Q1_position_y]) * 0.25);
}
else
{
// result
return $numbers[$Q1_position];
}
}
Expand All @@ -141,10 +144,12 @@ public static function quartilupper_inc_function(array $numbers)
{
$Q3_position_y = floor($Q3_position);
$Q3_position_x = ceil($Q3_position);
// result
return ($numbers[$Q3_position_y] + ($numbers[$Q3_position_x] - $numbers[$Q3_position_y]) * 0.75);
}
else
{
// result
return $numbers[$Q3_position];
}
}
Expand All @@ -159,10 +164,12 @@ public static function quartillower_exc_function(array $numbers)
{
$Q1_position_y = floor($Q1_position)-1;
$Q1_position_x = ceil($Q1_position)-1;
// result
return ($numbers[$Q1_position_y] + ($numbers[$Q1_position_x] - $numbers[$Q1_position_y]) * 0.75);
}
else
{
// result
return $numbers[$Q1_position];
}
}
Expand All @@ -177,21 +184,25 @@ public static function quartilupper_exc_function(array $numbers)
{
$Q3_position_y = floor($Q3_position)-1;
$Q3_position_x = ceil($Q3_position)-1;
// result
return ($numbers[$Q3_position_y] + ($numbers[$Q3_position_x] - $numbers[$Q3_position_y]) * 0.25);
}
else
{
// result
return $numbers[$Q3_position];
}
}

public static function interquartilerange_inc_function(array $numbers)
{
// result
return MathFormats::quartilupper_inc_function($numbers) - MathFormats::quartillower_inc_function($numbers);
}

public static function interquartilerange_exc_function(array $numbers)
{
// result
return MathFormats::quartilupper_exc_function($numbers) - MathFormats::quartillower_exc_function($numbers);
}

Expand Down Expand Up @@ -221,6 +232,7 @@ public static function mode_function(array $numbers)
// check if there are more than one max
if($count == 1)
{
// result
return $max;
}
}
Expand All @@ -229,7 +241,7 @@ public static function interquartilemean_function(array $numbers)
{
// sort numbers
sort($numbers,SORT_NUMERIC);
// check if size of numbers is divisble by 4
// check if size of numbers is divisible by 4
if(sizeof($numbers)%4 == 0)
{
// split array into 4 groups (2D array)
Expand All @@ -244,11 +256,12 @@ public static function interquartilemean_function(array $numbers)
{
$store_string += $array_split[2][$i];
}
// result
return $store_string/(sizeof($array_split[1])+sizeof($array_split[2]));
}
else
{
// get positon of split
// get position of split
$position = sizeof($numbers)/4;
// remove values out of split
for($i = 0; $i < floor($position); $i++)
Expand All @@ -264,6 +277,7 @@ public static function interquartilemean_function(array $numbers)
{
$store_values += $store_array[$i];
}
// result
return ($store_values + ((ceil($position) - $position) * ($store_array[0] + $store_array[sizeof($store_array)-1]))) / ($position*2);
}
}
Expand Down Expand Up @@ -332,7 +346,7 @@ protected function getResultText( SMWQueryResult $res, $outputmode ) {
return MathFormats::sum_function($numbers);
break;
case 'product':
return MathFormats::pruduct_function($numbers);
return MathFormats::product_function($numbers);
break;
case 'average':
return MathFormats::average_function($numbers);
Expand Down
Loading

0 comments on commit a54e8ce

Please sign in to comment.