IndexTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
  5. use PHPUnit\Framework\TestCase;
  6. class IndexTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider providerINDEX
  10. *
  11. * @param mixed $expectedResult
  12. */
  13. public function testINDEX($expectedResult, ...$args): void
  14. {
  15. $result = LookupRef::INDEX(/** @scrutinizer ignore-type */ ...$args);
  16. self::assertEquals($expectedResult, $result);
  17. }
  18. public function providerINDEX(): array
  19. {
  20. return require 'tests/data/Calculation/LookupRef/INDEX.php';
  21. }
  22. /**
  23. * @dataProvider providerIndexArray
  24. */
  25. public function testIndexArray(array $expectedResult, string $matrix, string $rows, string $columns): void
  26. {
  27. $calculation = Calculation::getInstance();
  28. $formula = "=INDEX({$matrix}, {$rows}, {$columns})";
  29. $result = $calculation->_calculateFormulaValue($formula);
  30. self::assertEquals($expectedResult, $result);
  31. }
  32. public function providerIndexArray(): array
  33. {
  34. return [
  35. 'row/column vectors' => [
  36. [[2, 3], [5, 6]],
  37. '{1, 2, 3; 4, 5, 6; 7, 8, 9}',
  38. '{1; 2}',
  39. '{2, 3}',
  40. ],
  41. 'return row' => [
  42. [1 => [4, 5, 6]],
  43. '{1, 2, 3; 4, 5, 6; 7, 8, 9}',
  44. '2',
  45. '0',
  46. ],
  47. 'return column' => [
  48. [[2], [5], [8]],
  49. '{1, 2, 3; 4, 5, 6; 7, 8, 9}',
  50. '0',
  51. '2',
  52. ],
  53. ];
  54. }
  55. }