Skip to content

Commit 765085c

Browse files
committed
Better graph everywhere
1 parent f674b5f commit 765085c

3 files changed

Lines changed: 64 additions & 45 deletions

File tree

algo/tests/test_ess_coverage.rs

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,44 @@ use dsi_progress_logger::no_logging;
99
use webgraph::graphs::vec_graph::VecGraph;
1010
use webgraph_algo::distances::exact_sum_sweep::{self, Level};
1111

12-
/// Directed graph with a cycle and a sink: 0→1→2→3→0, 2→4.
12+
/// Canonical test graph (8 nodes, 11 arcs).
13+
///
14+
/// - Outdegree 0: node 7 (sink)
15+
/// - Outdegree 1: nodes 2, 3, 4, 6
16+
/// - Outdegree 2: nodes 0, 5
17+
/// - Outdegree 3: node 1
18+
/// - Indegree 0: node 0 (source)
19+
/// - Indegree 1: nodes 1, 3, 5, 7
20+
/// - Indegree 2: nodes 2, 4
21+
/// - Indegree 3: node 6
22+
/// - Cycle: 2 → 4 → 6 → 2
1323
fn directed_graph() -> (VecGraph, VecGraph) {
14-
let graph = VecGraph::from_arcs([(0, 1), (1, 2), (2, 3), (3, 0), (2, 4)]);
15-
let transpose = VecGraph::from_arcs([(1, 0), (2, 1), (3, 2), (0, 3), (4, 2)]);
24+
let graph = VecGraph::from_arcs([
25+
(0, 1),
26+
(0, 2),
27+
(1, 3),
28+
(1, 4),
29+
(1, 5),
30+
(2, 4),
31+
(3, 6),
32+
(4, 6),
33+
(5, 6),
34+
(5, 7),
35+
(6, 2),
36+
]);
37+
let transpose = VecGraph::from_arcs([
38+
(1, 0),
39+
(2, 0),
40+
(3, 1),
41+
(4, 1),
42+
(5, 1),
43+
(4, 2),
44+
(6, 3),
45+
(6, 4),
46+
(6, 5),
47+
(7, 5),
48+
(2, 6),
49+
]);
1650
(graph, transpose)
1751
}
1852

@@ -34,34 +68,37 @@ fn symm_graph() -> VecGraph {
3468
fn test_ess_diameter_only() -> Result<()> {
3569
let (graph, transpose) = directed_graph();
3670
let result = exact_sum_sweep::Diameter::run(&graph, &transpose, None, no_logging![]);
37-
assert_eq!(result.diameter, 4);
71+
assert_eq!(result.diameter, 3);
3872
Ok(())
3973
}
4074

4175
#[test]
4276
fn test_ess_radius_only() -> Result<()> {
4377
let (graph, transpose) = directed_graph();
4478
let result = exact_sum_sweep::Radius::run(&graph, &transpose, None, no_logging![]);
45-
assert_eq!(result.radius, 3);
79+
assert_eq!(result.radius, 2);
4680
Ok(())
4781
}
4882

4983
#[test]
5084
fn test_ess_all_forward() -> Result<()> {
5185
let (graph, transpose) = directed_graph();
5286
let result = exact_sum_sweep::AllForward::run(&graph, &transpose, None, no_logging![]);
53-
assert_eq!(result.diameter, 4);
54-
assert_eq!(result.radius, 3);
55-
assert_eq!(result.forward_eccentricities.as_ref(), &[3, 3, 3, 4, 0]);
87+
assert_eq!(result.diameter, 3);
88+
assert_eq!(result.radius, 2);
89+
assert_eq!(
90+
result.forward_eccentricities.as_ref(),
91+
&[3, 3, 2, 3, 2, 3, 2, 0]
92+
);
5693
Ok(())
5794
}
5895

5996
#[test]
6097
fn test_ess_radius_diameter() -> Result<()> {
6198
let (graph, transpose) = directed_graph();
6299
let result = exact_sum_sweep::RadiusDiameter::run(&graph, &transpose, None, no_logging![]);
63-
assert_eq!(result.diameter, 4);
64-
assert_eq!(result.radius, 3);
100+
assert_eq!(result.diameter, 3);
101+
assert_eq!(result.radius, 2);
65102
Ok(())
66103
}
67104

webgraph/tests/test_breadth_first.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,17 @@ macro_rules! test_bfv_algo_seq {
7272
#[test]
7373
fn test_simple_graph() -> Result<()> {
7474
let arcs = vec![
75-
(0, 0),
76-
(1, 0),
77-
(1, 2),
78-
(2, 1),
79-
(2, 3),
75+
(0, 1),
76+
(0, 2),
77+
(1, 3),
78+
(1, 4),
79+
(1, 5),
8080
(2, 4),
81-
(2, 5),
82-
(3, 4),
83-
(4, 3),
84-
(5, 5),
81+
(3, 6),
82+
(4, 6),
8583
(5, 6),
8684
(5, 7),
87-
(5, 8),
88-
(6, 7),
89-
(8, 7),
85+
(6, 2),
9086
];
9187
let graph = VecGraph::from_arcs(arcs);
9288
let mut visit = $bfv(&graph);
@@ -222,21 +218,17 @@ macro_rules! test_bfv_algo_par {
222218
#[test]
223219
fn test_simple_graph() -> Result<()> {
224220
let arcs = vec![
225-
(0, 0),
226-
(1, 0),
227-
(1, 2),
228-
(2, 1),
229-
(2, 3),
221+
(0, 1),
222+
(0, 2),
223+
(1, 3),
224+
(1, 4),
225+
(1, 5),
230226
(2, 4),
231-
(2, 5),
232-
(3, 4),
233-
(4, 3),
234-
(5, 5),
227+
(3, 6),
228+
(4, 6),
235229
(5, 6),
236230
(5, 7),
237-
(5, 8),
238-
(6, 7),
239-
(8, 7),
231+
(6, 2),
240232
];
241233
let graph = VecGraph::from_arcs(arcs);
242234
let mut visit = $bfv(&graph);

webgraph/tests/test_visits_coverage.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ fn test_dfs_interrupted_visit_stack() -> Result<()> {
328328
});
329329
assert_eq!(interrupted_node, std::ops::ControlFlow::Break(3));
330330
// After interruption at node 3 on chain 0->1->2->3->4, the stack
331-
// yields the parents of nodes on the visit path (excluding the root),
331+
// yields the parents of nodes on the visit path (except for the last one),
332332
// in reverse order. The interrupted node (3) was never pushed.
333333
let stack_nodes: Vec<usize> = visit.stack().collect();
334334
assert_eq!(stack_nodes, vec![1, 0]);
@@ -961,16 +961,6 @@ fn test_bfs_order_disconnected_graph() {
961961
assert_eq!(events[0].root, 0);
962962
}
963963

964-
#[test]
965-
fn test_bfs_order_exact_size() {
966-
use webgraph::visits::breadth_first;
967-
968-
let graph = VecGraph::from_arcs([(0, 1), (1, 2)]);
969-
let mut visit = breadth_first::Seq::new(&graph);
970-
let order = breadth_first::BfsOrder::new(&mut visit);
971-
assert_eq!(order.len(), 3);
972-
}
973-
974964
#[test]
975965
fn test_bfs_order_from_roots() -> Result<()> {
976966
use webgraph::visits::breadth_first;

0 commit comments

Comments
 (0)