Beispiel #1
0
 /**
  *
  */
 public function testZiplLongest()
 {
     $longest = zip_longest(['A', 'B', 'C', 'D'], ['x', 'y']);
     $longest->setFillValue('-');
     $longest = to_array($longest);
     $this->assertSame([['A', 'x'], ['B', 'y'], ['C', '-'], ['D', '-']], $longest);
 }
 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 testCombinationsWithReplacement()
 {
     $combinations = combinations_with_replacement(['A', 'B', 'C'], 2);
     $results = to_array($combinations);
     $this->assertSame(6, count($results));
     $expected = 'AA AB AC BB BC CC';
     $results = array_map(function ($d) {
         return join('', $d);
     }, $results);
     $this->assertSame(preg_split("/[\\s,]+/", $expected), $results);
 }
Beispiel #4
0
 /**
  *
  */
 public function testMapMoreIterable()
 {
     $lambda = function (...$args) {
         return call_user_func('array_sum', $args);
     };
     $a = [1, 2, 3, 4];
     $b = [17, 12, 11, 10];
     $c = [-1, -4, 5, 9];
     $twoIterable = map($lambda, $a, $b);
     $threeIterable = map($lambda, $a, $b, $c);
     $this->assertSame([18, 14, 14, 14], to_array($twoIterable));
     $this->assertSame([17, 10, 19, 23], to_array($threeIterable));
 }
 /**
  *
  */
 public function testReversedFuncNonReverseable()
 {
     $array = ['a', 'b', 'c'];
     $reverse = reversed($array);
     $this->assertSame(['c', 'b', 'a'], to_array($reverse));
 }