ComplexMatrixTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace MathPHP\Tests\LinearAlgebra\Matrix\Complex;
  3. use MathPHP\Exception;
  4. use MathPHP\LinearAlgebra\ComplexMatrix;
  5. use MathPHP\Number\ArbitraryInteger;
  6. use MathPHP\Number\Complex;
  7. use MathPHP\Tests\LinearAlgebra\Fixture\MatrixDataProvider;
  8. class ComplexMatrixTest extends \PHPUnit\Framework\TestCase
  9. {
  10. use MatrixDataProvider;
  11. /**
  12. * @test Construction
  13. * @dataProvider dataProviderForComplexObjectMatrix
  14. * @param Complex[][]
  15. */
  16. public function testConstruction(array $A)
  17. {
  18. // When
  19. $A = new ComplexMatrix($A);
  20. // Then
  21. $this->assertInstanceOf(ComplexMatrix::class, $A);
  22. }
  23. /**
  24. * @test Constructor exception when non complex number provided
  25. */
  26. public function testConstructorException()
  27. {
  28. // Given
  29. $A = [
  30. [new Complex(2, 1), new Complex(2, 1)],
  31. [new Complex(2, 1), new ArbitraryInteger(4)],
  32. ];
  33. // Then
  34. $this->expectException(Exception\IncorrectTypeException::class);
  35. // When
  36. $A = new ComplexMatrix($A);
  37. }
  38. /**
  39. * @test createZeroValue
  40. */
  41. public function testCreateZeroValue()
  42. {
  43. // Given
  44. $zeroMatrix = ComplexMatrix::createZeroValue();
  45. // And
  46. $expected = [
  47. [new Complex(0, 0)]
  48. ];
  49. // Then
  50. $this->assertEquals($expected, $zeroMatrix->getMatrix());
  51. }
  52. /**
  53. * @test conjugateTranspose
  54. */
  55. public function testConjugateTranspose()
  56. {
  57. // Given
  58. $A = [
  59. [new Complex(1, 0), new Complex(-2, -1), new Complex(5, 0)],
  60. [new Complex(1, 1), new Complex(0, 1), new Complex(4, -2)],
  61. ];
  62. $A = new ComplexMatrix($A);
  63. // And
  64. $expected = [
  65. [new Complex(1, 0), new Complex(1, -1)],
  66. [new Complex(-2, 1), new Complex(0, -1)],
  67. [new Complex(5, 0), new Complex(4, 2)],
  68. ];
  69. // When
  70. $Aᴴ = $A->conjugateTranspose();
  71. // Then
  72. $this->assertEquals($expected, $Aᴴ->getMatrix());
  73. }
  74. }