icentral_test_basic_icentral/
test_basic_icentral.rs

1crate::ix!();
2
3pub const USE_ERDOS: bool = false;
4
5#[test] fn test_basic_icentral() -> Result<(), BetweennessCentralityError> {
6
7    setup_test_logger![];
8    
9    let start = Instant::now();
10
11    tracing::info!("Testing [iCentral] ... ");
12
13    let e: Edge = Edge::new_with_ids(3,7);
14
15    let mut graph: Graph = match USE_ERDOS {
16        true  => Graph::from_filename("icentral/Erdos02.lcc.net"),
17        false => Graph::from(GraphMock::Paper),
18    };
19
20    debug!("graph: {:#?}", graph);
21
22    // fill_test_graph(graph);
23    let mut scores = fast_brandes_bc(&graph)?;
24
25    info!("scores: {:?}", scores);
26
27    let mut component = Component::new_from_graph_ref(
28        &graph, 
29        "test_basic_icentral::component"
30    );
31
32    info!("component: {:#?}", component);
33
34    let mut delta_bc_of_vertices = BetweennessScores::new(
35        component.num_nodes(), 
36        "test_basic_icentral::delta_bc_of_vertices"
37    );
38
39    let num_threads = 1;
40
41    icentral(
42        num_threads, 
43        &mut delta_bc_of_vertices, 
44        arcmut![component], 
45        e, 
46        None
47    );
48
49    info!("delta_bc_of_vertices: {:?}",delta_bc_of_vertices);
50
51    for node in delta_bc_of_vertices.nodeid_range() {
52
53        scores.increase_score_for_node(
54            node, 
55            delta_bc_of_vertices.score_for_node(node)
56        );
57    }
58
59    info!("scores: {:?}", scores);
60
61    let mut mismatches = vec![];
62
63    debug!("if we insert this edge, it looks like we get mismatches...");
64
65    //graph.insert_edge(&e);
66
67    let ref_scores = brandes_bc(&mut graph, None)?;
68
69    info!("ref_scores: {:?}", ref_scores);
70
71    info!("checking for mismatches");
72
73    for node in scores.nodeid_range() {
74
75        let diff = (scores.score_for_node(node) - ref_scores.score_for_node(node)).abs();
76
77        if diff > EPS.into() {
78
79            mismatches.push(diff);
80        }
81
82        // debug!("[%f]  [%f]", scores.score_for_node(&v), ref_scores.score_for_node(&v));
83    }
84
85    for item in mismatches.iter() {
86
87        warn!("data mismatch! diff={}", item);
88    }
89
90    if mismatches.len() > 0 {
91
92        warn!("got {} mismatches!", mismatches.len());
93
94        return Err(
95            BCError::DataMismatches { mismatches }
96        );
97    }
98
99    info!("no mismatches -- success!");
100
101    let elapsed = Instant::now() - start;
102
103    info!("elapsed: {:?}", elapsed);
104
105    Ok(())
106}