| 77 | |
| 78 | #[test] |
| 79 | fn harmonic_path() { |
| 80 | // a - b - c. b has shortest distances to a (1) and c (1). |
| 81 | // HC(b) = (1/1 + 1/1) / 2 = 1.0 |
| 82 | // HC(a) = (1/1 + 1/2) / 2 = 0.75 |
| 83 | let mut csr = CsrIndex::new(); |
| 84 | csr.add_edge("a", "L", "b").unwrap(); |
| 85 | csr.add_edge("b", "L", "c").unwrap(); |
| 86 | csr.compact().expect("no governor, cannot fail"); |
| 87 | |
| 88 | let batch = run(&csr); |
| 89 | let json = batch.to_json().unwrap(); |
| 90 | let rows: Vec<serde_json::Value> = serde_json::from_slice(&json).unwrap(); |
| 91 | let map: std::collections::HashMap<&str, f64> = rows |
| 92 | .iter() |
| 93 | .map(|r| { |
| 94 | ( |
| 95 | r["node_id"].as_str().unwrap(), |
| 96 | r["centrality"].as_f64().unwrap(), |
| 97 | ) |
| 98 | }) |
| 99 | .collect(); |
| 100 | |
| 101 | assert!(map["b"] > map["a"]); |
| 102 | assert!(map["b"] > map["c"]); |
| 103 | } |
| 104 | |
| 105 | #[test] |
| 106 | fn harmonic_disconnected() { |