Skip to content

Commit 0311563

Browse files
authored
Adding Quickcheck for heavy hex graph (#1469)
To ensure the structural properties of heavy hex graph hold, we check that for every odd d < 31, The total number of nodes equals the theoretical count: ( 5 d 2 − 2 d − 1 ) / 2 (5d 2 −2d−1)/2 The total number of edges equals: 2 d ( d − 1 ) + ( d + 1 ) ( d − 1 ) 2d(d−1)+(d+1)(d−1)
1 parent d32e3d8 commit 0311563

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use petgraph::graph::UnGraph;
2+
use quickcheck::{quickcheck, TestResult};
3+
use rustworkx_core::generators::heavy_hex_graph;
4+
5+
#[test]
6+
fn prop_heavy_hex_structure() {
7+
fn prop(d: usize) -> TestResult {
8+
let d = (d % 31) | 1;
9+
if d == 0 {
10+
return TestResult::discard();
11+
}
12+
13+
let g = match heavy_hex_graph::<UnGraph<(), ()>, (), _, _, ()>(d, || (), || (), false) {
14+
Ok(g) => g,
15+
Err(_) => return TestResult::error("Unexpected error in graph generation"),
16+
};
17+
18+
let expected_nodes = (5 * d * d - 2 * d - 1) / 2;
19+
let expected_edges = 2 * d * (d - 1) + (d + 1) * (d - 1);
20+
21+
let node_ok = g.node_count() == expected_nodes;
22+
let edge_ok = g.edge_count() == expected_edges;
23+
24+
TestResult::from_bool(node_ok && edge_ok)
25+
}
26+
27+
quickcheck(prop as fn(usize) -> TestResult);
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod barbell_graph;
22
mod full_rary_tree_graph;
33
mod grid_graph;
4+
mod heavy_hex_graph;
45
mod lollipop_graph;

0 commit comments

Comments
 (0)