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 testCartesianIterable() { $product = new ProductIterator(range(2)); $product->setRepeat(3); $results = to_array($product); $this->assertSame(8, count($results)); $expected = '000 001 010 011 100 101 110 111'; $results = array_map(function ($d) { return join('', $d); }, $results); $this->assertSame(preg_split("/[\\s,]+/", $expected), $results); }