NumericMatrixTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace MathPHP\Tests\LinearAlgebra\Matrix\Numeric;
  3. use MathPHP\LinearAlgebra\NumericMatrix;
  4. class NumericMatrixTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /**
  7. * @test Object type of numeric matrix
  8. */
  9. public function testGetObjectType()
  10. {
  11. // Given
  12. $A = new NumericMatrix([
  13. [1, 2, 3],
  14. [2, 3, 4],
  15. [3, 4, 5],
  16. ]);
  17. // When
  18. $objectType = $A->getObjectType();
  19. // Then
  20. $this->assertSame('number', $objectType);
  21. }
  22. /**
  23. * @test string representation
  24. */
  25. public function testGetStringRepresentation()
  26. {
  27. // Given
  28. $A = new NumericMatrix([
  29. [1, 2, 3],
  30. [2, 3, 4],
  31. [3, 4, 5],
  32. ]);
  33. // And
  34. $expected = "[1, 2, 3]\n[2, 3, 4]\n[3, 4, 5]";
  35. // When
  36. $stringRepresentation = (string) $A;
  37. // Then
  38. $this->assertEquals($expected, $stringRepresentation);
  39. }
  40. /**
  41. * @test debug Info
  42. */
  43. public function testDebugInfo()
  44. {
  45. // Given
  46. $A = new NumericMatrix([
  47. [1, 2, 3, 4],
  48. [2, 3, 4, 5],
  49. [3, 4, 5, 6],
  50. ]);
  51. // When
  52. $debugInfo = $A->__debugInfo();
  53. // Then
  54. $this->assertEquals('3x4', $debugInfo['matrix']);
  55. $this->assertEquals(\PHP_EOL . (string) $A, $debugInfo['data']);
  56. $this->assertEquals($A->getError(), $debugInfo['ε']);
  57. }
  58. }