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

Function betweenness_path_graph

nodedb/src/engine/graph/algo/betweenness.rs:143–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141
142 #[test]
143 fn betweenness_path_graph() {
144 // a -> b -> c -> d (linear path)
145 // b and c are on all shortest paths between endpoints.
146 let mut csr = CsrIndex::new();
147 csr.add_edge("a", "L", "b").unwrap();
148 csr.add_edge("b", "L", "c").unwrap();
149 csr.add_edge("c", "L", "d").unwrap();
150 csr.compact().expect("no governor, cannot fail");
151
152 let batch = run(&csr, &AlgoParams::default());
153 let json = batch.to_json().unwrap();
154 let rows: Vec<serde_json::Value> = serde_json::from_slice(&json).unwrap();
155 let map: std::collections::HashMap<&str, f64> = rows
156 .iter()
157 .map(|r| {
158 (
159 r["node_id"].as_str().unwrap(),
160 r["centrality"].as_f64().unwrap(),
161 )
162 })
163 .collect();
164
165 // b and c should have highest betweenness (they bridge a-d).
166 assert!(map["b"] > map["a"]);
167 assert!(map["c"] > map["d"]);
168 // Endpoints have zero betweenness (no shortest paths pass through them).
169 assert!(map["a"].abs() < 1e-9);
170 assert!(map["d"].abs() < 1e-9);
171 }
172
173 #[test]
174 fn betweenness_triangle() {

Callers

nothing calls this directly

Calls 9

add_edgeMethod · 0.80
collectMethod · 0.80
runFunction · 0.70
expectMethod · 0.45
compactMethod · 0.45
to_jsonMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
as_f64Method · 0.45

Tested by

no test coverage detected