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

Function diameter_triangle

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

Source from the content-addressed store, hash-verified

178
179 #[test]
180 fn diameter_triangle() {
181 let mut csr = CsrIndex::new();
182 for (s, d) in &[("a", "b"), ("b", "c"), ("c", "a")] {
183 csr.add_edge(s, "L", d).unwrap();
184 }
185 csr.compact().expect("no governor, cannot fail");
186
187 let batch = run(
188 &csr,
189 &AlgoParams {
190 mode: Some("EXACT".into()),
191 ..Default::default()
192 },
193 );
194 let json = batch.to_json().unwrap();
195 let rows: Vec<serde_json::Value> = serde_json::from_slice(&json).unwrap();
196
197 // Directed triangle: diameter depends on direction. With undirected
198 // treatment, max distance is 1 (all directly connected).
199 let d = rows[0]["diameter"].as_i64().unwrap();
200 assert!((1..=2).contains(&d));
201 }
202
203 #[test]
204 fn diameter_approximate() {

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