ValidationTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace MathPHP\Tests\NumericalAnalysis\NumericalIntegration;
  3. use MathPHP\Exception;
  4. use MathPHP\NumericalAnalysis\NumericalIntegration\Validation;
  5. class ValidationTest extends \PHPUnit\Framework\TestCase
  6. {
  7. /**
  8. * @test isSpacingConstant
  9. * @dataProvider dataProviderForConstantSpacedPoints
  10. * @param array $points
  11. * @throws \Exception
  12. */
  13. public function testIsSpacingConstant(array $points)
  14. {
  15. // When
  16. Validation::isSpacingConstant($points);
  17. // Then
  18. $this->assertTrue(true);
  19. }
  20. /**
  21. * @return array
  22. */
  23. public function dataProviderForConstantSpacedPoints(): array
  24. {
  25. return [
  26. [
  27. []
  28. ],
  29. [
  30. [[0,0]]
  31. ],
  32. [
  33. [[0,0], [1,1]]
  34. ],
  35. [
  36. [[0,0], [1,1], [2,2], [3,3], [4,4], [5,5]]
  37. ],
  38. [
  39. [[0,2], [2,4], [4,6], [6,8], [8,10], [10,12]]
  40. ],
  41. [
  42. [[1,0], [4,1], [7,2], [10,3], [13,4], [16,5]]
  43. ],
  44. ];
  45. }
  46. /**
  47. * @test isSpacingConstant when not constant
  48. * @dataProvider dataProviderForNonConstantSpacedPoints
  49. * @param array $points
  50. * @throws \Exception
  51. */
  52. public function testIsSpacingConstantWhenNotConstant(array $points)
  53. {
  54. // Then
  55. $this->expectException(Exception\BadDataException::class);
  56. // When
  57. Validation::isSpacingConstant($points);
  58. }
  59. /**
  60. * @return array
  61. */
  62. public function dataProviderForNonConstantSpacedPoints(): array
  63. {
  64. return [
  65. [
  66. [[0,0], [1,1], [2,2], [5,3], [6,4], [7,5]]
  67. ],
  68. [
  69. [[0,2], [2,4], [4,6], [6,8], [8,10], [9,12]]
  70. ],
  71. [
  72. [[1,0], [4,1], [5,2], [10,3], [13,4], [15,5]]
  73. ],
  74. ];
  75. }
  76. /**
  77. * @test isSubintervalsMultiple
  78. * @dataProvider dataProviderForSubintervalsMultiple
  79. * @param array $points
  80. * @param int $m
  81. * @throws \Exception
  82. */
  83. public function testIsSubintervalsMultiple(array $points, int $m)
  84. {
  85. // When
  86. Validation::isSubintervalsMultiple($points, $m);
  87. // Then
  88. $this->assertTrue(true);
  89. }
  90. /**
  91. * @return array
  92. */
  93. public function dataProviderForSubintervalsMultiple(): array
  94. {
  95. return [
  96. [
  97. [[0,0], [1,1]],
  98. 1
  99. ],
  100. [
  101. [[0,0], [1,1], [2,2]],
  102. 2
  103. ],
  104. [
  105. [[0,2], [2,4], [4,6], [6,8]],
  106. 3
  107. ],
  108. [
  109. [[1,0], [4,1], [7,2], [10,3], [13,4], [16,5]],
  110. 5
  111. ],
  112. ];
  113. }
  114. /**
  115. * @test isSubintervalsMultiple when not a multiple of m
  116. * @dataProvider dataProviderForSubintervalsNotMultiple
  117. * @param array $points
  118. * @param int $m
  119. * @throws \Exception
  120. */
  121. public function testIsSubintervalsMultipleNotMultiple(array $points, int $m)
  122. {
  123. // Then
  124. $this->expectException(Exception\BadDataException::class);
  125. // When
  126. Validation::isSubintervalsMultiple($points, $m);
  127. }
  128. /**
  129. * @return array
  130. */
  131. public function dataProviderForSubintervalsNotMultiple(): array
  132. {
  133. return [
  134. [
  135. [[0,0], [1,1]],
  136. 2
  137. ],
  138. [
  139. [[0,0], [1,1], [2,2]],
  140. 3
  141. ],
  142. [
  143. [[0,2], [2,4], [4,6], [6,8]],
  144. 2
  145. ],
  146. [
  147. [[1,0], [4,1], [7,2], [10,3], [13,4], [16,5]],
  148. 9
  149. ],
  150. ];
  151. }
  152. }