Skip to content

Commit

Permalink
fix(clippy): put test module last in file
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Dec 29, 2024
1 parent e2fb157 commit 873624a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/undirected/kruskal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@ fn find(parents: &mut [usize], mut node: usize) -> usize {
node
}

#[cfg(test)]
mod tests {
use super::find;

#[test]
fn path_halving() {
let mut parents = vec![0, 0, 1, 2, 3, 4, 5, 6];
assert_eq!(find(&mut parents, 7), 0);
assert_eq!(parents, vec![0, 0, 1, 1, 3, 3, 5, 5]);
assert_eq!(find(&mut parents, 7), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 5, 3]);
assert_eq!(find(&mut parents, 7), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 5, 0]);
assert_eq!(find(&mut parents, 6), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 3, 0]);
assert_eq!(find(&mut parents, 6), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 0, 0]);
}
}

fn union(parents: &mut [usize], ranks: &mut [usize], mut a: usize, mut b: usize) {
if ranks[a] < ranks[b] {
mem::swap(&mut a, &mut b);
Expand Down Expand Up @@ -98,3 +78,23 @@ where
))
})
}

#[cfg(test)]
mod tests {
use super::find;

#[test]
fn path_halving() {
let mut parents = vec![0, 0, 1, 2, 3, 4, 5, 6];
assert_eq!(find(&mut parents, 7), 0);
assert_eq!(parents, vec![0, 0, 1, 1, 3, 3, 5, 5]);
assert_eq!(find(&mut parents, 7), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 5, 3]);
assert_eq!(find(&mut parents, 7), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 5, 0]);
assert_eq!(find(&mut parents, 6), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 3, 0]);
assert_eq!(find(&mut parents, 6), 0);
assert_eq!(parents, vec![0, 0, 1, 0, 3, 3, 0, 0]);
}
}

0 comments on commit 873624a

Please sign in to comment.