PermutationATest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  5. use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Permutations;
  6. use PHPUnit\Framework\TestCase;
  7. class PermutationATest extends TestCase
  8. {
  9. protected function setUp(): void
  10. {
  11. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  12. }
  13. /**
  14. * @dataProvider providerPERMUT
  15. *
  16. * @param mixed $expectedResult
  17. */
  18. public function testPERMUT($expectedResult, ...$args): void
  19. {
  20. $result = Permutations::PERMUTATIONA(...$args);
  21. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  22. }
  23. public function providerPERMUT(): array
  24. {
  25. return require 'tests/data/Calculation/Statistical/PERMUTATIONA.php';
  26. }
  27. /**
  28. * @dataProvider providerPermutationAArray
  29. */
  30. public function testPermutationAArray(array $expectedResult, string $argument1, string $argument2): void
  31. {
  32. $calculation = Calculation::getInstance();
  33. $formula = "=PERMUTATIONA({$argument1},{$argument2})";
  34. $result = $calculation->_calculateFormulaValue($formula);
  35. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  36. }
  37. public function providerPermutationAArray(): array
  38. {
  39. return [
  40. 'first argument row vector' => [
  41. [[512, 125]],
  42. '{8, 5}',
  43. '3',
  44. ],
  45. 'first argument column vector' => [
  46. [[512], [125]],
  47. '{8; 5}',
  48. '3',
  49. ],
  50. 'first argument matrix' => [
  51. [[512, 125], [27, 343]],
  52. '{8, 5; 3, 7}',
  53. '3',
  54. ],
  55. 'second argument row vector' => [
  56. [[2197, 4826809]],
  57. '13',
  58. '{3, 6}',
  59. ],
  60. 'second argument column vector' => [
  61. [[2197], [4826809]],
  62. '13',
  63. '{3; 6}',
  64. ],
  65. 'second argument matrix' => [
  66. [[2197, 4826809], [28561, 815730721]],
  67. '13',
  68. '{3, 6; 4, 8}',
  69. ],
  70. 'A row and a column vector' => [
  71. [
  72. [248832, 20736, 1728, 144],
  73. [100000, 10000, 1000, 100],
  74. [32768, 4096, 512, 64],
  75. [7776, 1296, 216, 36],
  76. ],
  77. '{12; 10; 8; 6}',
  78. '{5, 4, 3, 2}',
  79. ],
  80. 'Two row vectors' => [
  81. [[248832, 10000, 512, 36]],
  82. '{12, 10, 8, 6}',
  83. '{5, 4, 3, 2}',
  84. ],
  85. 'Two column vectors' => [
  86. [[248832], [10000], [512], [36]],
  87. '{12; 10; 8; 6}',
  88. '{5; 4; 3; 2}',
  89. ],
  90. ];
  91. }
  92. }