Skip to content

Commit af1c75c

Browse files
authored
Adding quickcheck for barbell graphs (#1467)
* Adding quickcheck for barbell graphs This QuickCheck test verifies structural properties of barbell_graph. It ensures the total number of nodes is 2 × mesh_size + path_size. It checks the number of edges matches the expected sum of two cliques, path edges, and connectors. * Fixing clippy issue
1 parent fb530db commit af1c75c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use petgraph::graph::UnGraph;
2+
use quickcheck::{quickcheck, TestResult};
3+
use rustworkx_core::generators::barbell_graph;
4+
5+
#[test]
6+
fn prop_barbell_graph_structure() {
7+
fn prop(mesh_size: usize, path_size: usize) -> TestResult {
8+
let mesh_size = mesh_size % 32 + 2;
9+
let path_size = path_size % 32;
10+
11+
let graph = match barbell_graph::<UnGraph<(), ()>, (), _, _, ()>(
12+
Some(mesh_size),
13+
Some(path_size),
14+
None,
15+
None,
16+
|| (),
17+
|| (),
18+
) {
19+
Ok(g) => g,
20+
Err(_) => return TestResult::error("Failed to generate barbell graph"),
21+
};
22+
23+
// Expected node count
24+
let expected_nodes = 2 * mesh_size + path_size;
25+
if graph.node_count() != expected_nodes {
26+
return TestResult::failed();
27+
}
28+
29+
// Expected edge count
30+
let mesh_edges = mesh_size * (mesh_size - 1) / 2;
31+
let path_edges = if path_size > 0 { path_size - 1 } else { 0 };
32+
let connectors = if path_size > 0 { 2 } else { 1 };
33+
let expected_edges = 2 * mesh_edges + path_edges + connectors;
34+
35+
if graph.edge_count() != expected_edges {
36+
return TestResult::failed();
37+
}
38+
39+
TestResult::passed()
40+
}
41+
42+
quickcheck(prop as fn(usize, usize) -> TestResult);
43+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
mod barbell_graph;
12
mod grid_graph;
23
mod lollipop_graph;

0 commit comments

Comments
 (0)