InterpolationTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace MathPHP\Tests\NumericalAnalysis\Interpolation;
  3. use MathPHP\NumericalAnalysis\Interpolation\Interpolation;
  4. use MathPHP\Exception;
  5. class InterpolationTest extends \PHPUnit\Framework\TestCase
  6. {
  7. /**
  8. * @test getPoints with incorrect type - source is neither a callback nor a set of arrays
  9. * @throws \Exception
  10. */
  11. public function testIncorrectInput()
  12. {
  13. // Given
  14. $x = 10;
  15. $incorrectFunction = $x ** 2 + 2 * $x + 1;
  16. // Then
  17. $this->expectException(Exception\BadDataException::class);
  18. // When
  19. Interpolation::getPoints($incorrectFunction, [0,4,5]);
  20. }
  21. /**
  22. * @test validate array doesn't have precisely two numbers (coordinates)
  23. * @throws \Exception
  24. */
  25. public function testNotCoordinatesException()
  26. {
  27. // Given
  28. $points = [[0,0], [1,2,3], [2,2]];
  29. // Then
  30. $this->expectException(Exception\BadDataException::class);
  31. // When
  32. Interpolation::validate($points);
  33. }
  34. /**
  35. * @test validate - not enough arrays in the input
  36. * @throws \Exception
  37. */
  38. public function testNotEnoughArraysException()
  39. {
  40. // Given
  41. $points = [[0,0]];
  42. // Then
  43. $this->expectException(Exception\BadDataException::class);
  44. // When
  45. Interpolation::validate($points);
  46. }
  47. /**
  48. * @test validate - two arrays share the same first number (x component)
  49. * @throws \Exception
  50. */
  51. public function testNotAFunctionException()
  52. {
  53. // Given
  54. $points = [[0,0], [0,5], [1,1]];
  55. // Then
  56. $this->expectException(Exception\BadDataException::class);
  57. // When
  58. Interpolation::validate($points);
  59. }
  60. }