MMultTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
  4. class MMultTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerMMULT
  8. *
  9. * @param mixed $expectedResult
  10. */
  11. public function testMMULT($expectedResult, ...$args): void
  12. {
  13. $result = MathTrig\MatrixFunctions::multiply(...$args);
  14. self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
  15. }
  16. public function providerMMULT(): array
  17. {
  18. return require 'tests/data/Calculation/MathTrig/MMULT.php';
  19. }
  20. public function testOnSpreadsheet(): void
  21. {
  22. // very limited ability to test this in the absence of dynamic arrays
  23. $sheet = $this->getSheet();
  24. $sheet->getCell('A1')->setValue('=MMULT({1,2,3}, {1,2,3})'); // incompatible dimensions
  25. self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue());
  26. $sheet->getCell('A11')->setValue('=MMULT({1, 2, 3, 4}, {5; 6; 7; 8})');
  27. self::assertEquals(70, $sheet->getCell('A11')->getCalculatedValue());
  28. $sheet->getCell('A2')->setValue(1);
  29. $sheet->getCell('B2')->setValue(2);
  30. $sheet->getCell('C2')->setValue(3);
  31. $sheet->getCell('D2')->setValue(4);
  32. $sheet->getCell('D3')->setValue(5);
  33. $sheet->getCell('D4')->setValue(6);
  34. $sheet->getCell('A12')->setValue('=MMULT(A2:C2,D2:D4)');
  35. self::assertEquals(32, $sheet->getCell('A12')->getCalculatedValue());
  36. }
  37. }