expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class); Average::weightedAverage([1, 2, 3, 4, 5, 6, 7], [0.1, 0.2, 0.3, 0.1, 0.2, 0.05]); } /** * @testdox An empty dataset for the arithmetic mean throws a ZeroDivisionException * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testInvalidArithmeticMeanZeroDivision() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::arithmeticMean([]); } /** * @testdox An empty dataset for the moving average throws a Exception * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testInvalidMovingAverageZeroDivision() : void { $this->expectException(\Exception::class); Average::movingAverage([], 4, 2); } /** * @testdox An empty dataset for the harmonic mean throws a ZeroDivisionException * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testInvalidHarmonicMeanZeroDivision() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::harmonicMean([]); } /** * @testdox An empty dataset for the geometric mean throws a ZeroDivisionException * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testInvalidGeometricMean() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::geometricMean([]); } /** * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testInvalidAngleMean() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::angleMean([]); } /** * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testInvalidAngleMean2() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::angleMean2([]); } /** * @testdox A dataset with a 0 element throws a ZeroDivisionException * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testInvalidHarmonicMean() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::harmonicMean([1, 2, 3, 0, 5, 6, 7]); } /** * @testdox The mode is correctly calculated * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testMode() : void { self::assertEqualsWithDelta(2, Average::mode([1, 2, 2, 3, 4, 4, 2]), 0.01); self::assertEqualsWithDelta(2, Average::mode([1, 2, 2, -1, -5, 3, 4, 4, 5, 9, 2], 2), 0.01); } /** * @testdox The median is correctly calculated * @covers phpOMS\Math\Statistic\Average * @group framework */ public function testMedian() : void { self::assertEqualsWithDelta(4, Average::median([1, 2, 3, 4, 5, 6, 7]), 0.01); self::assertEqualsWithDelta(4, Average::median([1, 2, -4, -6, 8, 9, 3, 4, 5, 6, 7], 2), 0.01); self::assertEqualsWithDelta(3.5, Average::median([1, 2, 3, 4, 5, 6]), 0.01); } }