Skip to content

Commit d32e3d8

Browse files
authored
Adding Quickcheck full rary graph (#1468)
* 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. * Adding quickcheck for full rary tree We add quickcheck to test the following properties of a full rary tree graph: Node count is exactly num_nodes Edge count is at most num_nodes - 1 (a tree has n-1 edges) * Adding quickcheck test for full rary tree graph The quickcheck tests for the following properties: Node count is exactly num_nodes. Edge count is at most num_nodes - 1 (a tree has n-1 edges).
1 parent af1c75c commit d32e3d8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use petgraph::graph::UnGraph;
2+
use quickcheck::{quickcheck, TestResult};
3+
use rustworkx_core::generators::full_rary_tree_graph;
4+
5+
#[test]
6+
fn prop_full_rary_tree_structure() {
7+
fn prop(branching: usize, num_nodes: usize) -> TestResult {
8+
let branching = branching % 10 + 1;
9+
let num_nodes = num_nodes % 100;
10+
11+
if num_nodes == 0 {
12+
return TestResult::discard();
13+
}
14+
15+
let graph = match full_rary_tree_graph::<UnGraph<(), ()>, (), _, _, ()>(
16+
branching,
17+
num_nodes,
18+
None,
19+
|| (),
20+
|| (),
21+
) {
22+
Ok(g) => g,
23+
Err(_) => return TestResult::error("Unexpected error in tree generation"),
24+
};
25+
26+
// Property 1: Node count must match
27+
if graph.node_count() != num_nodes {
28+
return TestResult::failed();
29+
}
30+
31+
// Property 2: Edge count must be exactly n - 1
32+
if graph.edge_count() != num_nodes - 1 {
33+
return TestResult::failed();
34+
}
35+
36+
TestResult::passed()
37+
}
38+
39+
quickcheck(prop as fn(usize, usize) -> TestResult);
40+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mod barbell_graph;
2+
mod full_rary_tree_graph;
23
mod grid_graph;
34
mod lollipop_graph;

0 commit comments

Comments
 (0)