<commit_before><?php

namespace Knp\Menu\Tests\Iterator;

use Knp\Menu\Iterator\RecursiveItemIterator;
use Knp\Menu\Tests\TestCase;

class IteratorTest extends TestCase
{
    public function testIterator()
    {
        $count = 0;
        foreach ($this->pt1 as $key => $value) {
            $count++;
            $this->assertEquals('Child '.$count, $key);
            $this->assertEquals('Child '.$count, $value->getLabel());
        }
    }

    public function testRecursiveIterator()
    {
        // Adding an item which does not provide a RecursiveIterator to be sure it works properly.
        $child = $this->getMock('Knp\Menu\ItemInterface');
        $child->expects($this->any())
            ->method('getName')
            ->will($this->returnValue('Foo'));
        $child->expects($this->any())
            ->method('getIterator')
            ->will($this->returnValue(new \EmptyIterator()));
        $this->menu->addChild($child);

        $names = array();
        foreach (new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::SELF_FIRST) as $value) {
            $names[] = $value->getName();
        }

        $this->assertEquals(array('Parent 1', 'Child 1', 'Child 2', 'Child 3', 'Parent 2', 'Child 4', 'Grandchild 1', 'Foo'), $names);
    }

    public function testRecursiveIteratorLeavesOnly()
    {
        $names = array();
        foreach (new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::LEAVES_ONLY) as $value) {
            $names[] = $value->getName();
        }

        $this->assertEquals(array('Child 1', 'Child 2', 'Child 3', 'Grandchild 1'), $names);
    }
}
<commit_msg>Added a test as an example of iteration on all items of the tree<commit_after><?php

namespace Knp\Menu\Tests\Iterator;

use Knp\Menu\Iterator\RecursiveItemIterator;
use Knp\Menu\Tests\TestCase;

class IteratorTest extends TestCase
{
    public function testIterator()
    {
        $count = 0;
        foreach ($this->pt1 as $key => $value) {
            $count++;
            $this->assertEquals('Child '.$count, $key);
            $this->assertEquals('Child '.$count, $value->getLabel());
        }
    }

    public function testRecursiveIterator()
    {
        // Adding an item which does not provide a RecursiveIterator to be sure it works properly.
        $child = $this->getMock('Knp\Menu\ItemInterface');
        $child->expects($this->any())
            ->method('getName')
            ->will($this->returnValue('Foo'));
        $child->expects($this->any())
            ->method('getIterator')
            ->will($this->returnValue(new \EmptyIterator()));
        $this->menu->addChild($child);

        $names = array();
        foreach (new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::SELF_FIRST) as $value) {
            $names[] = $value->getName();
        }

        $this->assertEquals(array('Parent 1', 'Child 1', 'Child 2', 'Child 3', 'Parent 2', 'Child 4', 'Grandchild 1', 'Foo'), $names);
    }

    public function testRecursiveIteratorLeavesOnly()
    {
        $names = array();
        foreach (new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::LEAVES_ONLY) as $value) {
            $names[] = $value->getName();
        }

        $this->assertEquals(array('Child 1', 'Child 2', 'Child 3', 'Grandchild 1'), $names);
    }

    public function testFullTreeIterator()
    {
        $fullTreeIterator = new \RecursiveIteratorIterator(
            new RecursiveItemIterator(new \ArrayIterator(array($this->menu))), // recursive iterator containing the root item
            \RecursiveIteratorIterator::SELF_FIRST
        );

        $names = array();
        foreach ($fullTreeIterator as $value) {
            $names[] = $value->getName();
        }

        $this->assertEquals(array('Root li', 'Parent 1', 'Child 1', 'Child 2', 'Child 3', 'Parent 2', 'Child 4', 'Grandchild 1'), $names);
    }
}

{'fraction_non_alphanumeric': 0.15690168818272096, 'fraction_numerical': 0.008192651439920555, 'mean_word_length': 2.747906976744186, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '126281', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1140, 'n_words': 266}