You are here

protected function GraphTest::normalizeGraph in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::normalizeGraph()
  2. 10 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::normalizeGraph()

Normalizes a graph.

Parameters

$graph: A graph array processed by \Drupal\Component\Graph\Graph::searchAndSort()

Return value

array The normalized version of a graph.

1 call to GraphTest::normalizeGraph()
GraphTest::testDepthFirstSearch in core/tests/Drupal/Tests/Component/Graph/GraphTest.php
Tests depth-first-search features.

File

core/tests/Drupal/Tests/Component/Graph/GraphTest.php, line 91

Class

GraphTest
@coversDefaultClass \Drupal\Component\Graph\Graph @group Graph

Namespace

Drupal\Tests\Component\Graph

Code

protected function normalizeGraph($graph) {
  $normalized_graph = [];
  foreach ($graph as $vertex => $edges) {

    // Create vertex even if it hasn't any edges.
    $normalized_graph[$vertex] = [];
    foreach ($edges as $edge) {
      $normalized_graph[$vertex]['edges'][$edge] = TRUE;
    }
  }
  return $normalized_graph;
}