CombinATest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class CombinATest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerCOMBINA
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $numObjs
  11. * @param mixed $numInSet
  12. */
  13. public function testCOMBINA($expectedResult, $numObjs, $numInSet): void
  14. {
  15. $this->mightHaveException($expectedResult);
  16. $sheet = $this->getSheet();
  17. if ($numObjs !== null) {
  18. $sheet->getCell('A1')->setValue($numObjs);
  19. }
  20. if ($numInSet !== null) {
  21. $sheet->getCell('A2')->setValue($numInSet);
  22. }
  23. $sheet->getCell('B1')->setValue('=COMBINA(A1,A2)');
  24. $result = $sheet->getCell('B1')->getCalculatedValue();
  25. self::assertEquals($expectedResult, $result);
  26. }
  27. public function providerCOMBINA(): array
  28. {
  29. return require 'tests/data/Calculation/MathTrig/COMBINA.php';
  30. }
  31. /**
  32. * @dataProvider providerCombinAArray
  33. */
  34. public function testCombinAArray(array $expectedResult, string $argument1, string $argument2): void
  35. {
  36. $calculation = Calculation::getInstance();
  37. $formula = "=COMBINA({$argument1},{$argument2})";
  38. $result = $calculation->_calculateFormulaValue($formula);
  39. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  40. }
  41. public function providerCombinAArray(): array
  42. {
  43. return [
  44. 'first argument row vector' => [
  45. [[120, 35]],
  46. '{8, 5}',
  47. '3',
  48. ],
  49. 'first argument column vector' => [
  50. [[120], [35]],
  51. '{8; 5}',
  52. '3',
  53. ],
  54. 'first argument matrix' => [
  55. [[120, 35], [10, 84]],
  56. '{8, 5; 3, 7}',
  57. '3',
  58. ],
  59. 'second argument row vector' => [
  60. [[455, 18564]],
  61. '13',
  62. '{3, 6}',
  63. ],
  64. 'second argument column vector' => [
  65. [[455], [18564]],
  66. '13',
  67. '{3; 6}',
  68. ],
  69. 'second argument matrix' => [
  70. [[455, 18564], [1820, 125970]],
  71. '13',
  72. '{3, 6; 4, 8}',
  73. ],
  74. 'A row and a column vector' => [
  75. [
  76. [4368, 1365, 364, 78],
  77. [2002, 715, 220, 55],
  78. [792, 330, 120, 36],
  79. [252, 126, 56, 21],
  80. ],
  81. '{12; 10; 8; 6}',
  82. '{5, 4, 3, 2}',
  83. ],
  84. 'Two row vectors' => [
  85. [[4368, 715, 120, 21]],
  86. '{12, 10, 8, 6}',
  87. '{5, 4, 3, 2}',
  88. ],
  89. 'Two column vectors' => [
  90. [[4368], [715], [120], [21]],
  91. '{12; 10; 8; 6}',
  92. '{5; 4; 3; 2}',
  93. ],
  94. ];
  95. }
  96. }