CombinTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class CombinTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerCOMBIN
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $numObjs
  11. * @param mixed $numInSet
  12. */
  13. public function testCOMBIN($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('=COMBIN(A1,A2)');
  24. $result = $sheet->getCell('B1')->getCalculatedValue();
  25. self::assertEquals($expectedResult, $result);
  26. }
  27. public function providerCOMBIN(): array
  28. {
  29. return require 'tests/data/Calculation/MathTrig/COMBIN.php';
  30. }
  31. /**
  32. * @dataProvider providerCombinArray
  33. */
  34. public function testCombinArray(array $expectedResult, string $argument1, string $argument2): void
  35. {
  36. $calculation = Calculation::getInstance();
  37. $formula = "=COMBIN({$argument1},{$argument2})";
  38. $result = $calculation->_calculateFormulaValue($formula);
  39. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  40. }
  41. public function providerCombinArray(): array
  42. {
  43. return [
  44. 'first argument row vector' => [
  45. [[56, 10]],
  46. '{8, 5}',
  47. '3',
  48. ],
  49. 'first argument column vector' => [
  50. [[56], [10]],
  51. '{8; 5}',
  52. '3',
  53. ],
  54. 'first argument matrix' => [
  55. [[56, 10], [1, 35]],
  56. '{8, 5; 3, 7}',
  57. '3',
  58. ],
  59. 'second argument row vector' => [
  60. [[286, 1716]],
  61. '13',
  62. '{3, 6}',
  63. ],
  64. 'second argument column vector' => [
  65. [[286], [1716]],
  66. '13',
  67. '{3; 6}',
  68. ],
  69. 'second argument matrix' => [
  70. [[286, 1716], [715, 1287]],
  71. '13',
  72. '{3, 6; 4, 8}',
  73. ],
  74. 'A row and a column vector' => [
  75. [
  76. [792, 495, 220, 66],
  77. [252, 210, 120, 45],
  78. [56, 70, 56, 28],
  79. [6, 15, 20, 15],
  80. ],
  81. '{12; 10; 8; 6}',
  82. '{5, 4, 3, 2}',
  83. ],
  84. 'Two row vectors' => [
  85. [[792, 210, 56, 15]],
  86. '{12, 10, 8, 6}',
  87. '{5, 4, 3, 2}',
  88. ],
  89. 'Two column vectors' => [
  90. [[792], [210], [56], [15]],
  91. '{12; 10; 8; 6}',
  92. '{5; 4; 3; 2}',
  93. ],
  94. ];
  95. }
  96. }