VandermondeMatrixTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace MathPHP\Tests\LinearAlgebra\Matrix\Other;
  3. use MathPHP\LinearAlgebra\MatrixFactory;
  4. class VandermondeMatrixTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /**
  7. * @test Vandermonde matrix is constructed correctly
  8. * @dataProvider dataProviderForTestConstructor
  9. * @param array $M
  10. * @param int $n
  11. * @param array $V
  12. * @throws \Exception
  13. */
  14. public function testConstructor(array $M, int $n, array $V)
  15. {
  16. // Given
  17. $V = MatrixFactory::create($V);
  18. // When
  19. $M = MatrixFactory::vandermonde($M, $n);
  20. // Then
  21. $this->assertTrue($V->isEqual($M));
  22. $this->assertTrue($M->isEqual($V));
  23. }
  24. /**
  25. * @return array
  26. */
  27. public function dataProviderForTestConstructor(): array
  28. {
  29. return [
  30. [
  31. [1, 2, 3, 4], 4,
  32. [
  33. [1, 1, 1, 1],
  34. [1, 2, 4, 8],
  35. [1, 3, 9, 27],
  36. [1, 4, 16, 64],
  37. ],
  38. ],
  39. [
  40. [10, 5, 4], 3,
  41. [
  42. [1, 10, 100],
  43. [1, 5, 25],
  44. [1, 4, 16],
  45. ],
  46. ],
  47. ];
  48. }
  49. }