Skip to content

Commit 6a6724a

Browse files
committed
feat(tests): add some edge tests
1 parent 4ec42ae commit 6a6724a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/graph/eulerian_path.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::vec::Vec;
1313
/// * `edges` - A vector of tuples representing the directed edges in the graph, where each tuple
1414
/// is of the form `(u, v)` indicating a directed edge from `u` to `v`.
1515
///
16+
/// The function checks if an Eulerian path exists and, if so, constructs and returns one valid path.
17+
///
1618
/// # Returns
1719
///
1820
/// An `Option` containing a vector representing the Eulerian path if it exists, or `None` if no such path exists.
@@ -339,5 +341,39 @@ mod tests {
339341
],
340342
None::<Vec<usize>>
341343
),
344+
test_single_edge: (
345+
2,
346+
vec![(0, 1)],
347+
Some(vec![0, 1])
348+
),
349+
test_multiple_eulerian_paths: (
350+
4,
351+
vec![
352+
(0, 1),
353+
(1, 2),
354+
(2, 0),
355+
(0, 3),
356+
(3, 0)
357+
],
358+
Some(vec![0, 3, 0, 1, 2, 0])
359+
),
360+
test_dag_path: (
361+
4,
362+
vec![
363+
(0, 1),
364+
(1, 2),
365+
(2, 3)
366+
],
367+
Some(vec![0, 1, 2, 3])
368+
),
369+
test_parallel_edges_case: (
370+
2,
371+
vec![
372+
(0, 1),
373+
(0, 1),
374+
(1, 0)
375+
],
376+
Some(vec![0, 1, 0, 1])
377+
),
342378
}
343379
}

0 commit comments

Comments
 (0)