NumericalIntegrationTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace MathPHP\Tests\NumericalAnalysis\NumericalIntegration;
  3. use MathPHP\NumericalAnalysis\NumericalIntegration\NumericalIntegration;
  4. use MathPHP\Exception;
  5. class NumericalIntegrationTest extends \PHPUnit\Framework\TestCase
  6. {
  7. /**
  8. * @test The input $source is neither a callback or a set of arrays
  9. * @throws Exception\BadDataException
  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. NumericalIntegration::getPoints($incorrectFunction, [0,4,5]);
  20. }
  21. /**
  22. * @test An array doesn't have precisely two numbers (coordinates)
  23. * @throws Exception\BadDataException
  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. NumericalIntegration::validate($points);
  33. }
  34. /**
  35. * @test There are not enough arrays in the input
  36. * @throws Exception\BadDataException
  37. */
  38. public function testNotEnoughArraysException()
  39. {
  40. // Given
  41. $points = [[0,0]];
  42. // Then
  43. $this->expectException(Exception\BadDataException::class);
  44. // When
  45. NumericalIntegration::validate($points);
  46. }
  47. /**
  48. * @test Two arrays share the same first number (x-component)
  49. * @throws Exception\BadDataException
  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. NumericalIntegration::validate($points);
  59. }
  60. }