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

Function sssp_diamond_graph

nodedb/src/engine/graph/algo/sssp.rs:269–290  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

267
268 #[test]
269 fn sssp_diamond_graph() {
270 // Diamond: a -> b (1), a -> c (4), b -> d (2), c -> d (1)
271 // Shortest a->d: a->b->d = 3 (not a->c->d = 5)
272 let mut csr = CsrIndex::new();
273 csr.add_edge_weighted("a", "R", "b", 1.0).unwrap();
274 csr.add_edge_weighted("a", "R", "c", 4.0).unwrap();
275 csr.add_edge_weighted("b", "R", "d", 2.0).unwrap();
276 csr.add_edge_weighted("c", "R", "d", 1.0).unwrap();
277 csr.compact().expect("no governor, cannot fail");
278
279 let params = AlgoParams {
280 source_node: Some("a".into()),
281 ..Default::default()
282 };
283 let batch = run(&csr, &params).unwrap();
284 let dists = parse_results(&batch);
285
286 assert_eq!(dists["a"], 0.0);
287 assert_eq!(dists["b"], 1.0);
288 assert_eq!(dists["c"], 4.0);
289 assert_eq!(dists["d"], 3.0); // via b
290 }
291
292 #[test]
293 fn sssp_rejects_negative_weights() {

Callers

nothing calls this directly

Calls 5

parse_resultsFunction · 0.85
add_edge_weightedMethod · 0.80
runFunction · 0.70
expectMethod · 0.45
compactMethod · 0.45

Tested by

no test coverage detected