public function testCartesianProductIterable() { $product = new ProductIterator(str_split('ABCD'), str_split('xy')); $dumped = to_array($product); $this->assertSame([['A', 'x'], ['A', 'y'], ['B', 'x'], ['B', 'y'], ['C', 'x'], ['C', 'y'], ['D', 'x'], ['D', 'y']], $dumped); $cartesian = new ProductIterator(\range(0, 2)); $cartesian->setRepeat(3); $dumped = to_array($cartesian); }
/** * */ public function testCombinations() { $combinations = combinations(range(4), 3); $results = to_array($combinations); $this->assertSame(4, count($results)); $expected = '012 013 023 123'; $results = array_map(function ($d) { return join('', $d); }, $results); $this->assertSame(preg_split("/[\\s,]+/", $expected), $results); }