<commit_before><?php

use Fhaculty\Graph\Vertex;

use Fhaculty\Graph\GraphViz;
use Fhaculty\Graph\Edge\Base as Edge;
use Fhaculty\Graph\Algorithm\ShortestPath\BreadthFirst;
use Fhaculty\Graph\Loader\CompleteGraph;
use Fhaculty\Graph\Set\Vertices;

class BreadthFirstTest extends PHPUnit_Framework_TestCase
{
    public function testOne()
    {
        // TODO: this should NOT be part of the unit test
        // TODO: remove randomness
        $debug = false;

        $loader = new CompleteGraph(10);
        $loader->setEnableDirectedEdges(true);
        $graph = $loader->createGraph();

        // randomly remove 70% of the edges
        foreach (array_slice(Edge::getAll($graph->getEdges(), Edge::ORDER_RANDOM), 0, $graph->getNumberOfEdges()*0.8) as $edge) {
            $edge->destroy();
        }

        $start = $graph->getVertices()->getVertexOrder(Vertices::ORDER_RANDOM);
        $start->setLayoutAttribute('shape', 'doublecircle');

        // actually start breadth search
        $alg = new BreadthFirst($start);

        // visualize all resulting edges in blue
        foreach ($alg->getEdges() as $edge) {
            $edge->setLayoutAttribute('color', 'blue');
        }

        // visualize all reachable vertices in blue
        foreach ($alg->getVertices() as $vertex) {
            $vertex->setLayoutAttribute('color', 'blue');
        }

        if ($debug) {
            // visualize resulting graph
            $vis = new GraphViz($graph);
            $vis->display();
        }

        $this->assertTrue(count($alg->getVertices()) >= count($start->getVerticesEdgeTo()));

        // test all reachable vertices
        foreach ($alg->getDistanceMap() as $vid => $distance) {
            if($debug) echo 'vertex ' . $vid . ' in distance ' . $distance;
            $walk = $alg->getWalkTo($graph->getVertex($vid));

            $this->assertEquals($distance, $walk->getNumberOfEdges());

            if ($debug) {
                echo ' (vertex walk: ' . implode(', ', $walk->getVerticesSequenceId()) . ')';
                echo PHP_EOL;

                $vis = new GraphViz($walk->createGraph());
                $vis->display();
            }
        }

        // $alg = new BreadthFirst($startVertex);
    }
}<commit_msg>Update reference to Walk::getVerticesSequenceId()<commit_after><?php

use Fhaculty\Graph\Vertex;

use Fhaculty\Graph\GraphViz;
use Fhaculty\Graph\Edge\Base as Edge;
use Fhaculty\Graph\Algorithm\ShortestPath\BreadthFirst;
use Fhaculty\Graph\Loader\CompleteGraph;
use Fhaculty\Graph\Set\Vertices;

class BreadthFirstTest extends PHPUnit_Framework_TestCase
{
    public function testOne()
    {
        // TODO: this should NOT be part of the unit test
        // TODO: remove randomness
        $debug = false;

        $loader = new CompleteGraph(10);
        $loader->setEnableDirectedEdges(true);
        $graph = $loader->createGraph();

        // randomly remove 70% of the edges
        foreach (array_slice(Edge::getAll($graph->getEdges(), Edge::ORDER_RANDOM), 0, $graph->getNumberOfEdges()*0.8) as $edge) {
            $edge->destroy();
        }

        $start = $graph->getVertices()->getVertexOrder(Vertices::ORDER_RANDOM);
        $start->setLayoutAttribute('shape', 'doublecircle');

        // actually start breadth search
        $alg = new BreadthFirst($start);

        // visualize all resulting edges in blue
        foreach ($alg->getEdges() as $edge) {
            $edge->setLayoutAttribute('color', 'blue');
        }

        // visualize all reachable vertices in blue
        foreach ($alg->getVertices() as $vertex) {
            $vertex->setLayoutAttribute('color', 'blue');
        }

        if ($debug) {
            // visualize resulting graph
            $vis = new GraphViz($graph);
            $vis->display();
        }

        $this->assertTrue(count($alg->getVertices()) >= count($start->getVerticesEdgeTo()));

        // test all reachable vertices
        foreach ($alg->getDistanceMap() as $vid => $distance) {
            if($debug) echo 'vertex ' . $vid . ' in distance ' . $distance;
            $walk = $alg->getWalkTo($graph->getVertex($vid));

            $this->assertEquals($distance, $walk->getNumberOfEdges());

            if ($debug) {
                echo ' (vertex walk: ' . implode(', ', $walk->getVertices()->getVerticesDistinct()->getIds()) . ')';
                echo PHP_EOL;

                $vis = new GraphViz($walk->createGraph());
                $vis->display();
            }
        }

        // $alg = new BreadthFirst($startVertex);
    }
}
{'fraction_non_alphanumeric': 0.14488947253228276, 'fraction_numerical': 0.003064127817903261, 'mean_word_length': 2.3309037900874636, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, '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': '3632926', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1288, 'n_words': 281}