protected function GraphTest::assertReversePaths

Verify expected reverse paths in a graph.

Parameters

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

$expected_reverse_paths: An associative array containing vertices with their expected reverse paths.

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

File

drupal/core/tests/Drupal/Tests/Component/Graph/GraphTest.php, line 142
Contains \Drupal\Tests\Component\Graph\GraphTest.

Class

GraphTest
Unit tests for the graph handling features.

Namespace

Drupal\Tests\Component\Graph

Code

protected function assertReversePaths($graph, $expected_reverse_paths) {
  foreach ($expected_reverse_paths as $vertex => $paths) {

    // Build an array with keys = $paths and values = TRUE.
    $expected = array_fill_keys($paths, TRUE);
    $result = isset($graph[$vertex]['reverse_paths']) ? $graph[$vertex]['reverse_paths'] : array();
    $this
      ->assertEquals($expected, $result, sprintf('Expected reverse paths for vertex %s: %s, got %s', $vertex, $this
      ->displayArray($expected, TRUE), $this
      ->displayArray($result, TRUE)));
  }
}