Пример #1
0
 public static function shrinkLoop(RoseTree $tree)
 {
     $nodes = FP::realize($tree->getChildren());
     $smallest = $tree->getRoot();
     $visited = 0;
     $depth = 0;
     for ($i = 0; $i < count($nodes); ++$i) {
         $head = $nodes[$i];
         $root = $head->getRoot();
         $result = $root['result'];
         if (!$result || $result instanceof \Exception) {
             $children = FP::realize($head->getChildren());
             if (empty($children)) {
                 $smallest = $root;
                 $visited++;
             } else {
                 $nodes = $children;
                 $i = -1;
                 $smallest = $root;
                 $visited++;
                 $depth++;
             }
         } else {
             $visited++;
         }
     }
     return self::smallestShrink($visited, $depth, $smallest);
 }
 function testRewindBeforeGeneratorIsConsumed()
 {
     $range = new RewindableIterator(FP::range(0, 3));
     $range->rewind();
     $this->assertTrue($range->valid());
     $this->assertEquals(0, $range->current());
     $range->next();
     $this->assertTrue($range->valid());
     $this->assertEquals(1, $range->current());
     $range->rewind();
     $this->assertTrue($range->valid());
     $this->assertEquals(0, $range->current());
     $range->next();
     $this->assertTrue($range->valid());
     $this->assertEquals(1, $range->current());
     $range->next();
     $this->assertTrue($range->valid());
     $this->assertEquals(2, $range->current());
     $range->next();
     $this->assertFalse($range->valid());
     $range->rewind();
     $this->assertTrue($range->valid());
     $this->assertEquals(0, $range->current());
 }