function GraphUnitTest::assertComponents in SimpleTest 7
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 tests/
graph.test - Test depth-first-search features.
File
- tests/
graph.test, line 146 - Provides unit tests for graph.inc.
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)), t('Expected one unique component for vertices @vertices, got @components', array(
'@vertices' => $this
->displayArray($component),
'@components' => $this
->displayArray($result_components),
)));
}
$this
->assertEqual(array(), $unassigned_vertices, t('Vertices not assigned to a component: @vertices', array(
'@vertices' => $this
->displayArray($unassigned_vertices, TRUE),
)));
}