当前位置: 首页>>代码示例>>PHP>>正文


PHP Combination::getCombinations方法代码示例

本文整理汇总了PHP中Combination::getCombinations方法的典型用法代码示例。如果您正苦于以下问题:PHP Combination::getCombinations方法的具体用法?PHP Combination::getCombinations怎么用?PHP Combination::getCombinations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Combination的用法示例。


在下文中一共展示了Combination::getCombinations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCombinationsInstance

 public function testCombinationsInstance()
 {
     $mathCombination = new Combination();
     // Size 0 combinations ---------------------------------------------------------------------
     $combinationList0 = $mathCombination->getCombinations($this->_sourceDataSetKey, 0);
     $expectedList0 = [];
     $this->_assertCombination($combinationList0, $expectedList0, 0);
     // Size 1 combinations ---------------------------------------------------------------------
     $combinationList1 = $mathCombination->getCombinations($this->_sourceDataSetKey, 1);
     $expectedList1 = [['a' => 5], ['b' => 6], ['c' => 8], ['d' => 10]];
     $this->_assertCombination($combinationList1, $expectedList1, 4, 1);
     // If this test pass, we don't need to check for other Index arrays as it proves that the
     // combination is still treated as a map and thus if the key arrays tests pass, so would the
     // indexed arrays
     $combinationIdxList1 = $mathCombination->getCombinations($this->_sourceDataSetIdx, 1);
     $expectedIdxList1 = [[0 => 5], [1 => 6], [2 => 8], [3 => 10]];
     $this->_assertCombination($combinationIdxList1, $expectedIdxList1, 4, 1);
     // Size 3 combinations ---------------------------------------------------------------------
     $combinationList3 = $mathCombination->getCombinations($this->_sourceDataSetKey, 3);
     $expectedList3 = [['a' => 5, 'b' => 6, 'c' => 8], ['a' => 5, 'b' => 6, 'd' => 10], ['a' => 5, 'c' => 8, 'd' => 10], ['b' => 6, 'c' => 8, 'd' => 10]];
     $this->_assertCombination($expectedList3, $combinationList3, 4, 3);
     // Size 4 combinations ---------------------------------------------------------------------
     $combinationList4 = $mathCombination->getCombinations($this->_sourceDataSetKey, 4);
     $expectedList4 = [['a' => 5, 'b' => 6, 'c' => 8, 'd' => 10]];
     $this->_assertCombination($expectedList4, $combinationList4, 1, 4);
     // All combinations ------------------------------------------------------------------------
     $combinationList = $mathCombination->getCombinations($this->_sourceDataSetKey);
     $expectedList = [['a' => 5], ['b' => 6], ['c' => 8], ['d' => 10], ['a' => 5, 'b' => 6], ['a' => 5, 'c' => 8], ['a' => 5, 'd' => 10], ['b' => 6, 'c' => 8], ['b' => 6, 'd' => 10], ['c' => 8, 'd' => 10], ['a' => 5, 'b' => 6, 'c' => 8], ['a' => 5, 'b' => 6, 'd' => 10], ['a' => 5, 'c' => 8, 'd' => 10], ['b' => 6, 'c' => 8, 'd' => 10], ['a' => 5, 'b' => 6, 'c' => 8, 'd' => 10]];
     $this->_assertCombination($expectedList, $combinationList, 15);
 }
开发者ID:alphazygma,项目名称:combinatorics,代码行数:30,代码来源:CombinationTest.php


注:本文中的Combination::getCombinations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。