function GraphUnitTest::assertComponents

Verify expected components in a graph.

Parameters

$graph: A graph array processed by drupal_depth_first_search().

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

1 call to GraphUnitTest::assertComponents()
GraphUnitTest::testDepthFirstSearch in modules/simpletest/tests/graph.test
Test depth-first-search features.

File

modules/simpletest/tests/graph.test, line 148

Class

GraphUnitTest
Unit tests for the graph handling features.

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),
    )));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.