Skip to content

Commit a8cbfd8

Browse files
committed
Fine tuning parameter types in tests
1 parent 4826e13 commit a8cbfd8

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/Stat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ private static function ranks(array $data): array
677677
$indexed[] = [$data[$i], $i];
678678
}
679679

680-
usort($indexed, fn ($a, $b) => $a[0] <=> $b[0]);
680+
usort($indexed, fn(array $a, array $b): int => $a[0] <=> $b[0]);
681681

682682
$ranks = array_fill(0, $n, 0.0);
683683
$i = 0;

tests/StatTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,15 @@ public function test_calculates_spearman_correlation_planets(): void
403403

404404
// Linear (Pearson) correlation is imperfect
405405
$correlation = Stat::correlation($orbitalPeriod, $distFromSun);
406+
$this->assertIsFloat($correlation);
406407
$this->assertEquals(0.9882, round($correlation, 4));
407408

408409
// Kepler's third law: linear correlation between
409410
// the square of the period and the cube of the distance
410-
$periodSquared = array_map(fn ($p) => $p * $p, $orbitalPeriod);
411-
$distCubed = array_map(fn ($d) => $d * $d * $d, $distFromSun);
411+
$periodSquared = array_map(fn(int $p): int => $p * $p, $orbitalPeriod);
412+
$distCubed = array_map(fn(int $d): int => $d * $d * $d, $distFromSun);
412413
$correlation = Stat::correlation($periodSquared, $distCubed);
414+
$this->assertIsFloat($correlation);
413415
$this->assertEquals(1.0, round($correlation, 4));
414416
}
415417

0 commit comments

Comments
 (0)