php-ml/tests/Phpml/Math/Statistic/StandardDeviationTest.php
Tomáš Votruba a348111e97 Add PHPStan and level to max (#168)
* tests: update to PHPUnit 6.0 with rector

* fix namespaces on tests

* composer + tests: use standard test namespace naming

* update travis

* resolve conflict

* phpstan lvl 2

* phpstan lvl 3

* phpstan lvl 4

* phpstan lvl 5

* phpstan lvl 6

* phpstan lvl 7

* level max

* resolve conflict

* [cs] clean empty docs

* composer: bump to PHPUnit 6.4

* cleanup

* composer + travis: add phpstan

* phpstan lvl 1

* composer: update dev deps

* phpstan fixes

* update Contributing with new tools

* docs: link fixes, PHP version update

* composer: drop php-cs-fixer, cs already handled by ecs

* ecs: add old set rules

* [cs] apply rest of rules
2018-01-06 13:09:33 +01:00

41 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Phpml\Tests\Math\Statistic;
use Phpml\Exception\InvalidArgumentException;
use Phpml\Math\Statistic\StandardDeviation;
use PHPUnit\Framework\TestCase;
class StandardDeviationTest extends TestCase
{
public function testStandardDeviationOfPopulationSample(): void
{
//https://pl.wikipedia.org/wiki/Odchylenie_standardowe
$delta = 0.001;
$population = [5, 6, 8, 9];
$this->assertEquals(1.825, StandardDeviation::population($population), '', $delta);
//http://www.stat.wmich.edu/s216/book/node126.html
$delta = 0.5;
$population = [7100, 15500, 4400, 4400, 5900, 4600, 8800, 2000, 2750, 2550, 960, 1025];
$this->assertEquals(4079, StandardDeviation::population($population), '', $delta);
$population = [9300, 10565, 15000, 15000, 17764, 57000, 65940, 73676, 77006, 93739, 146088, 153260];
$this->assertEquals(50989, StandardDeviation::population($population), '', $delta);
}
public function testThrowExceptionOnEmptyArrayIfNotSample(): void
{
$this->expectException(InvalidArgumentException::class);
StandardDeviation::population([], false);
}
public function testThrowExceptionOnToSmallArray(): void
{
$this->expectException(InvalidArgumentException::class);
StandardDeviation::population([1]);
}
}