MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / diameter_approximate

Function diameter_approximate

nodedb/src/engine/graph/algo/diameter.rs:204–220  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202
203 #[test]
204 fn diameter_approximate() {
205 let mut csr = CsrIndex::new();
206 csr.add_edge("a", "L", "b").unwrap();
207 csr.add_edge("b", "L", "c").unwrap();
208 csr.add_edge("c", "L", "d").unwrap();
209 csr.add_edge("d", "L", "e").unwrap();
210 csr.compact().expect("no governor, cannot fail");
211
212 // Approximate should give a reasonable result.
213 let batch = run(&csr, &AlgoParams::default());
214 let json = batch.to_json().unwrap();
215 let rows: Vec<serde_json::Value> = serde_json::from_slice(&json).unwrap();
216
217 let d = rows[0]["diameter"].as_i64().unwrap();
218 // Double-sweep gives exact result for paths.
219 assert_eq!(d, 4);
220 }
221
222 #[test]
223 fn diameter_empty() {

Callers

nothing calls this directly

Calls 6

add_edgeMethod · 0.80
runFunction · 0.70
expectMethod · 0.45
compactMethod · 0.45
to_jsonMethod · 0.45
as_i64Method · 0.45

Tested by

no test coverage detected