Skip to content

Commit 4dd066d

Browse files
Adding Quickcheck for DGM graph (#1474)
Added quickcheck to test the structural properties of DGM graph, by checking its number of edges and nodes. Co-authored-by: Ivan Carvalho <[email protected]>
1 parent 5ecfdb7 commit 4dd066d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use petgraph::graph::Graph;
2+
use quickcheck::{quickcheck, TestResult};
3+
use rustworkx_core::generators::dorogovtsev_goltsev_mendes_graph;
4+
5+
#[test]
6+
fn prop_dgm_graph_structure() {
7+
fn prop(n: u8) -> TestResult {
8+
let n = (n % 7) as usize;
9+
let g: Graph<(), ()> = match dorogovtsev_goltsev_mendes_graph(n, || (), || ()) {
10+
Ok(graph) => graph,
11+
Err(_) => return TestResult::error("Failed to generate DGM graph"),
12+
};
13+
14+
let expected_edges = 3_usize.pow(n as u32);
15+
let expected_nodes = (expected_edges + 3) / 2;
16+
17+
if g.node_count() != expected_nodes || g.edge_count() != expected_edges {
18+
return TestResult::failed();
19+
}
20+
21+
TestResult::passed()
22+
}
23+
24+
quickcheck(prop as fn(u8) -> TestResult);
25+
}

rustworkx-core/tests/quickcheck/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod barbell_graph;
22
mod binomial_tree_graph;
33
mod complete_graph;
44
mod cycle_graph;
5+
mod dorogovtsev_goltsev_mendes_graph;
56
mod full_rary_tree_graph;
67
mod grid_graph;
78
mod heavy_hex_graph;

0 commit comments

Comments
 (0)