Skip to content

Commit

Permalink
style fine tuning (PER)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Oct 28, 2023
1 parent f51c393 commit 5a7a7cf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/ArrUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public static function stripZeroes(array $data): array
{
$del_val = 0;

return array_values(array_filter($data, fn ($e): bool => $e != $del_val));
return array_values(array_filter($data, fn($e): bool => $e != $del_val));
}
}
4 changes: 2 additions & 2 deletions tests/FrequenciesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
$s = Statistics::make(
[]
);
expect(fn () => $s->firstQuartile())->toThrow(InvalidDataInputException::class);
expect(fn() => $s->firstQuartile())->toThrow(InvalidDataInputException::class);
});
it('can calculate thirdQuartile', function () {
$s = Statistics::make(
Expand All @@ -78,5 +78,5 @@
$s = Statistics::make(
[]
);
expect(fn () => $s->thirdQuartile())->toThrow(InvalidDataInputException::class);
expect(fn() => $s->thirdQuartile())->toThrow(InvalidDataInputException::class);
});
52 changes: 26 additions & 26 deletions tests/StatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Stat::mean([-1.0, 2.5, 3.25, 5.75])
)->toEqual(2.625);
expect(
fn () => Stat::mean([])
fn() => Stat::mean([])
)->toThrow(InvalidDataInputException::class);
});

Expand All @@ -23,7 +23,7 @@
Stat::median([1, 3, 5, 7])
)->toEqual(4);
expect(
fn () => Stat::median([])
fn() => Stat::median([])
)->toThrow(InvalidDataInputException::class);
});
it('can calculate median low (static)', function () {
Expand All @@ -34,7 +34,7 @@
Stat::medianLow([1, 3, 5, 7])
)->toEqual(3);
expect(
fn () => Stat::medianLow([])
fn() => Stat::medianLow([])
)->toThrow(InvalidDataInputException::class);
});
it('can calculate median high (static)', function () {
Expand All @@ -45,7 +45,7 @@
Stat::medianHigh([1, 3, 5, 7])
)->toEqual(5);
expect(
fn () => Stat::medianHigh([])
fn() => Stat::medianHigh([])
)->toThrow(InvalidDataInputException::class);
});

Expand All @@ -54,7 +54,7 @@
Stat::mode([1, 1, 2, 3, 3, 3, 3, 4])
)->toEqual(3);
expect(
fn () => Stat::mode([])
fn() => Stat::mode([])
)->toThrow(InvalidDataInputException::class);
expect(
Stat::mode([1, 2, 3])
Expand Down Expand Up @@ -89,7 +89,7 @@
$result[2]
)->toEqual('f');
expect(
fn () => Stat::multimode([])
fn() => Stat::multimode([])
)->toThrow(InvalidDataInputException::class);
});
it('calculates Population standard deviation (static)', function () {
Expand All @@ -100,7 +100,7 @@
Stat::pstdev([1, 2, 4, 5, 8], 4)
)->toEqual(2.4495);
expect(
fn () => Stat::pstdev([])
fn() => Stat::pstdev([])
)->toThrow(InvalidDataInputException::class);
expect(
Stat::pstdev([1])
Expand All @@ -120,10 +120,10 @@
Stat::stdev([1, 2, 4, 5, 8], 4)
)->toEqual(2.7386);
expect(
fn () => Stat::stdev([])
fn() => Stat::stdev([])
)->toThrow(InvalidDataInputException::class);
expect(
fn () => Stat::stdev([1])
fn() => Stat::stdev([1])
)->toThrow(InvalidDataInputException::class);
});

Expand All @@ -147,7 +147,7 @@
Stat::geometricMean([54, 24, 36], 2)
)->toEqual(36);
expect(
fn () => Stat::geometricMean([])
fn() => Stat::geometricMean([])
)->toThrow(InvalidDataInputException::class);
});
it('calculates harmonic mean (static)', function () {
Expand All @@ -164,7 +164,7 @@
Stat::harmonicMean([60, 40], [7, 3], 1)
)->toEqual(52.2);
expect(
fn () => Stat::harmonicMean([])
fn() => Stat::harmonicMean([])
)->toThrow(InvalidDataInputException::class);
});

Expand All @@ -186,18 +186,18 @@
expect($q[1])->toEqual(2);
expect($q[2])->toEqual(4);
expect(
fn () => Stat::quantiles([1])
fn() => Stat::quantiles([1])
)->toThrow(InvalidDataInputException::class);
expect(
fn () => Stat::quantiles([1, 2, 3], 0)
fn() => Stat::quantiles([1, 2, 3], 0)
)->toThrow(InvalidDataInputException::class);
});

it('calculates first quartiles (static)', function () {
$q = Stat::firstQuartile([98, 90, 70, 18, 92, 92, 55, 83, 45, 95, 88, 76]);
expect($q)->toEqual(58.75);
expect(
fn () => Stat::firstQuartile([])
fn() => Stat::firstQuartile([])
)->toThrow(InvalidDataInputException::class);
});

Expand All @@ -223,35 +223,35 @@

it('calculates covariance, wrong usage (static)', function () {
expect(
fn () => Stat::covariance(
fn() => Stat::covariance(
[9, 8, 7, 6, 5, 4, 3, 2, 1],
[1, 2, 3, 4, 5, 6, 7, 8]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::covariance(
fn() => Stat::covariance(
[],
[]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::covariance(
fn() => Stat::covariance(
[3],
[3]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::covariance(
fn() => Stat::covariance(
['a', 1],
['b', 2]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::covariance(
fn() => Stat::covariance(
[3, 1],
['b', 2]
)
Expand Down Expand Up @@ -290,28 +290,28 @@

it('calculates correlation, wrong usage (static)', function () {
expect(
fn () => Stat::correlation(
fn() => Stat::correlation(
[9, 8, 7, 6, 5, 4, 3, 2, 1],
[1, 2, 3, 4, 5, 6, 7, 8]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::correlation(
fn() => Stat::correlation(
[],
[]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::correlation(
fn() => Stat::correlation(
[3],
[3]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::correlation(
fn() => Stat::correlation(
[3, 1, 2],
[2, 2, 2]
)
Expand Down Expand Up @@ -344,21 +344,21 @@

it('calculates linear regression with not valid input (static)', function () {
expect(
fn () => Stat::linearRegression(
fn() => Stat::linearRegression(
[3],
[2]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::linearRegression(
fn() => Stat::linearRegression(
[3, 3, 3, 3],
[2, 1, 1, 1, 1]
)
)->toThrow(InvalidDataInputException::class);

expect(
fn () => Stat::linearRegression(
fn() => Stat::linearRegression(
[3, 3, 3, 3, 3],
[1, 1, 1, 1, 1]
)
Expand Down
14 changes: 7 additions & 7 deletions tests/StatisticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
[]
);
expect($s->count())->toEqual(0);
expect(fn (): float|int|null => $s->mean())->toThrow(InvalidDataInputException::class);
expect(fn(): float|int|null => $s->mean())->toThrow(InvalidDataInputException::class);
});

it('can calculate mean again', function (): void { // https://docs.python.org/3/library/statistics.html#statistics.mean
Expand Down Expand Up @@ -128,7 +128,7 @@
Statistics::make([1, 2, 4, 5, 8])->pstdev(4)
)->toEqual(2.4495);
expect(
fn (): float => Statistics::make([])->pstdev()
fn(): float => Statistics::make([])->pstdev()
)->toThrow(InvalidDataInputException::class);
expect(
Statistics::make([1])->pstdev()
Expand All @@ -148,10 +148,10 @@
Statistics::make([1, 2, 4, 5, 8])->stdev(4)
)->toEqual(2.7386);
expect(
fn (): float => Statistics::make([])->stdev()
fn(): float => Statistics::make([])->stdev()
)->toThrow(InvalidDataInputException::class);
expect(
fn (): float => Statistics::make([1])->stdev()
fn(): float => Statistics::make([1])->stdev()
)->toThrow(InvalidDataInputException::class);
});

Expand All @@ -178,7 +178,7 @@
Statistics::make([4, 8, 3, 9, 17])->geometricMean(2)
)->toEqual(6.81);
expect(
fn (): float => Statistics::make([])->geometricMean()
fn(): float => Statistics::make([])->geometricMean()
)->toThrow(InvalidDataInputException::class);
});

Expand All @@ -187,13 +187,13 @@
Statistics::make([40, 60])->harmonicMean(1)
)->toEqual(48.0);
expect(
fn (): float => Statistics::make([])->harmonicMean()
fn(): float => Statistics::make([])->harmonicMean()
)->toThrow(InvalidDataInputException::class);
});

it('can distinct numeric array', function (): void {
expect(Statistics::make([1, 2, 3])->numericalArray())->toEqual([1, 2, 3]);
expect(Statistics::make([1, '2', 3])->numericalArray())->toEqual([1, '2', 3]);
expect(Statistics::make([])->numericalArray())->toEqual([]);
expect(fn (): array => Statistics::make([1, 'some string', 3])->numericalArray())->toThrow(InvalidDataInputException::class);
expect(fn(): array => Statistics::make([1, 'some string', 3])->numericalArray())->toThrow(InvalidDataInputException::class);
});

0 comments on commit 5a7a7cf

Please sign in to comment.