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]); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('An empty dataset for the arithmetic mean throws a ZeroDivisionException')] public function testInvalidArithmeticMeanZeroDivision() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::arithmeticMean([]); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('An empty dataset for the moving average throws a Exception')] public function testInvalidMovingAverageZeroDivision() : void { $this->expectException(\Exception::class); Average::movingAverage([], 4, 2); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('An empty dataset for the harmonic mean throws a ZeroDivisionException')] public function testInvalidHarmonicMeanZeroDivision() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::harmonicMean([]); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('An empty dataset for the geometric mean throws a ZeroDivisionException')] public function testInvalidGeometricMean() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::geometricMean([]); } #[\PHPUnit\Framework\Attributes\Group('framework')] public function testInvalidAngleMean() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::angleMean([]); } #[\PHPUnit\Framework\Attributes\Group('framework')] public function testInvalidAngleMean2() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::angleMean2([]); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('A dataset with a 0 element throws a ZeroDivisionException')] public function testInvalidHarmonicMean() : void { $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); Average::harmonicMean([1, 2, 3, 0, 5, 6, 7]); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('The mode is correctly calculated')] 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); } #[\PHPUnit\Framework\Attributes\Group('framework')] #[\PHPUnit\Framework\Attributes\TestDox('The median is correctly calculated')] 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); } }