VandermondeSquareMatrixTest.php 1.4 KB

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