Summary
dsatur_coloring tracks the highest assigned color in max_color and returns max_color + 1 as the number of used colors.
When the input graph is empty, no node is ever colored, max_color stays at its sentinel value, and the function still returns 1. And yet, an empty graph uses zero colors.
Expected behavior
The color count should be 0 when no node was colored.
Concrete regression test
use petgraph::{Graph, Undirected, algo::dsatur_coloring};
#[test]
fn dsatur_coloring_empty_graph_uses_zero_colors() {
let graph: Graph<(), (), Undirected> = Graph::new_undirected();
let (coloring, nb_colors) = dsatur_coloring(&graph);
assert!(coloring.is_empty());
assert_eq!(nb_colors, 0);
}
This currently fails because dsatur_coloring(&graph) returns (empty_map, 1) for an empty graph.
Suggested fix
Special-case the empty graph or derive the count from whether any color assignment actually happened.
Summary
dsatur_coloringtracks the highest assigned color inmax_colorand returnsmax_color + 1as the number of used colors.When the input graph is empty, no node is ever colored,
max_colorstays at its sentinel value, and the function still returns1. And yet, an empty graph uses zero colors.Expected behavior
The color count should be
0when no node was colored.Concrete regression test
This currently fails because
dsatur_coloring(&graph)returns(empty_map, 1)for an empty graph.Suggested fix
Special-case the empty graph or derive the count from whether any color assignment actually happened.