function GraphUnitTest::assertComponents

Verify expected components in a graph.

Parameters

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

$expected_components: An array containing of components defined as a list of their vertices.

1 call to GraphUnitTest::assertComponents()
GraphUnitTest::testDepthFirstSearch in drupal/core/modules/system/lib/Drupal/system/Tests/Graph/GraphUnitTest.php
Test depth-first-search features.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Graph/GraphUnitTest.php, line 152
Definition of Drupal\system\Tests\Graph\GraphUnitTest.

Class

GraphUnitTest
Unit tests for the graph handling features.

Namespace

Drupal\system\Tests\Graph

Code

function assertComponents($graph, $expected_components) {
  $unassigned_vertices = array_fill_keys(array_keys($graph), TRUE);
  foreach ($expected_components as $component) {
    $result_components = array();
    foreach ($component as $vertex) {
      $result_components[] = $graph[$vertex]['component'];
      unset($unassigned_vertices[$vertex]);
    }
    $this
      ->assertEqual(1, count(array_unique($result_components)), format_string('Expected one unique component for vertices @vertices, got @components', array(
      '@vertices' => $this
        ->displayArray($component),
      '@components' => $this
        ->displayArray($result_components),
    )));
  }
  $this
    ->assertEqual(array(), $unassigned_vertices, format_string('Vertices not assigned to a component: @vertices', array(
    '@vertices' => $this
      ->displayArray($unassigned_vertices, TRUE),
  )));
}