Skip to content

Commit 63c3f8c

Browse files
Krishn1412IvanIsCoding
authored andcommitted
Added property checks for lollipop graph (Qiskit#1453)
* Added property checks for lollipop graph Added a test using QuickCheck to verify that the lollipop_graph generator produces graphs with the correct number of nodes and edges based on the input sizes of the mesh and path. Updated the Cargo.toml to add dependecies and test target. * Update based on comment * Updates based on comments * Lint issue fixed * Update main.rs --------- Co-authored-by: Ivan Carvalho <[email protected]>
1 parent 1d9275f commit 63c3f8c

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

Cargo.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustworkx-core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ rand_distr.workspace = true
2525
rand_pcg.workspace = true
2626
rayon.workspace = true
2727
rayon-cond = "0.4"
28+
29+
[dev-dependencies]
30+
quickcheck = "1.0"
31+
quickcheck_macros = "1.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod special_graph;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use petgraph::graph::UnGraph;
2+
use quickcheck::{quickcheck, TestResult};
3+
use rustworkx_core::generators::lollipop_graph;
4+
5+
#[test]
6+
fn prop_lollipop_graph_structure() {
7+
fn prop(mesh_size: usize, path_size: usize) -> TestResult {
8+
// Constrain input space for sanity
9+
let mesh_size = mesh_size % 64;
10+
let path_size = path_size % 64;
11+
12+
if mesh_size + path_size == 0 {
13+
return TestResult::discard();
14+
}
15+
if mesh_size <= 1 {
16+
return TestResult::discard();
17+
}
18+
19+
let graph = match lollipop_graph::<UnGraph<(), ()>, (), _, _, ()>(
20+
Some(mesh_size),
21+
Some(path_size),
22+
None,
23+
None,
24+
|| (),
25+
|| (),
26+
) {
27+
Ok(g) => g,
28+
Err(_) => return TestResult::error("Unexpected error in graph generation"),
29+
};
30+
31+
let expected_nodes = mesh_size + path_size;
32+
let mesh_edges = mesh_size * (mesh_size - 1) / 2;
33+
let path_edges = path_size.saturating_sub(1);
34+
let connector = if path_size > 0 { 1 } else { 0 };
35+
let expected_edges = mesh_edges + path_edges + connector;
36+
37+
let node_match = graph.node_count() == expected_nodes;
38+
let edge_match = graph.edge_count() == expected_edges;
39+
40+
TestResult::from_bool(node_match && edge_match)
41+
}
42+
43+
quickcheck(prop as fn(usize, usize) -> TestResult);
44+
}

0 commit comments

Comments
 (0)