-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented
sample_variance
to aggregate rules (#53)
Added the "Sample Variance" rule to the set of aggregate rules. Changes reflect in the schema files (JSON, PHP, YAML), with a new PHP class for the rule and updates to existing tests. The README's rules count has been updated as well.
- Loading branch information
Showing
8 changed files
with
107 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Rules\Aggregate; | ||
|
||
use MathPHP\Statistics\Descriptive; | ||
|
||
final class ComboSampleVariance extends AbstarctAggregateRuleCombo | ||
{ | ||
protected const NAME = 'population variance'; | ||
|
||
protected const HELP_TOP = [ | ||
'Unbiased sample variance Use when only a subset of all possible observations of the system are present.', | ||
'n - 1 degrees of freedom, where n is the number of observations.', | ||
]; | ||
|
||
protected function getActualAggregate(array $colValues): ?float | ||
{ | ||
return Descriptive::sampleVariance(self::stringsToFloat($colValues)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\PHPUnit\Rules\Aggregate; | ||
|
||
use JBZoo\CsvBlueprint\Rules\AbstarctRule as Combo; | ||
use JBZoo\CsvBlueprint\Rules\Aggregate\ComboSampleVariance; | ||
use JBZoo\PHPUnit\Rules\AbstractAggregateRuleCombo; | ||
|
||
use function JBZoo\PHPUnit\isSame; | ||
|
||
class ComboSampleVarianceTest extends AbstractAggregateRuleCombo | ||
{ | ||
protected string $ruleClass = ComboSampleVariance::class; | ||
|
||
public function testEqual(): void | ||
{ | ||
$rule = $this->create(10.5, Combo::EQ); | ||
isSame('', $rule->test([13, 18, 13, 14, 13, 16, 14, 21, 10])); | ||
|
||
$rule = $this->create(10, Combo::EQ); | ||
isSame( | ||
'The population variance in the column is "10.5", which is not equal than the expected "10"', | ||
$rule->test([13, 18, 13, 14, 13, 16, 14, 21, 10]), | ||
); | ||
} | ||
} |