LeastSquaresTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace MathPHP\Tests\Statistics\Regression;
  3. use MathPHP\Statistics\Regression\Linear;
  4. use MathPHP\Exception;
  5. class LeastSquaresTest extends \PHPUnit\Framework\TestCase
  6. {
  7. /**
  8. * @test LeastSquares trait leastSquares method throws a BadDataException if degrees of freedom is ≤ 0
  9. * That will happen if there are only one or two points being used to fit a regression line.
  10. * @dataProvider dataProviderForLeastSquaresDegreesOfFreedomBadDataException
  11. * @param array $points
  12. */
  13. public function testLeastSquaresDegreesOfFreedomBadDataException(array $points)
  14. {
  15. // Then
  16. $this->expectException(Exception\BadDataException::class);
  17. // When
  18. $regression = new Linear($points);
  19. }
  20. /**
  21. * @return array [points]
  22. */
  23. public function dataProviderForLeastSquaresDegreesOfFreedomBadDataException(): array
  24. {
  25. return [
  26. 'zero_points' => [
  27. [],
  28. ],
  29. 'one_point' => [
  30. [[1, 2]],
  31. ],
  32. 'two_points' => [
  33. [[1, 2], [2, 3]],
  34. ]
  35. ];
  36. }
  37. }