Skip to content

Commit d490bfe

Browse files
authored
Move tests for bubble sort to match standard (TheAlgorithms#174)
* Add git hooks to check format and test run * Move tests for bubble sort to match standard
1 parent 3d40469 commit d490bfe

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

Diff for: .gitconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[core]
2+
hooksPath = git_hooks

Diff for: git_hooks/pre-commit

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cargo fmt
2+
cargo test

Diff for: src/lib.rs

-16
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,4 @@ mod tests {
2525
assert!(ve2[i] <= ve2[i + 1]);
2626
}
2727
}
28-
#[test]
29-
fn bubble_sort() {
30-
//descending
31-
let mut ve1 = vec![6, 5, 4, 3, 2, 1];
32-
sorting::bubble_sort(&mut ve1);
33-
for i in 0..ve1.len() - 1 {
34-
assert!(ve1[i] <= ve1[i + 1]);
35-
}
36-
37-
//pre-sorted
38-
let mut ve2 = vec![1, 2, 3, 4, 5, 6];
39-
sorting::bubble_sort(&mut ve2);
40-
for i in 0..ve2.len() - 1 {
41-
assert!(ve2[i] <= ve2[i + 1]);
42-
}
43-
}
4428
}

Diff for: src/sorting/bubble_sort.rs

+25
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,28 @@ pub fn bubble_sort<T: Ord>(arr: &mut [T]) {
77
}
88
}
99
}
10+
11+
#[cfg(test)]
12+
mod tests {
13+
use super::*;
14+
15+
#[test]
16+
fn descending() {
17+
//descending
18+
let mut ve1 = vec![6, 5, 4, 3, 2, 1];
19+
bubble_sort(&mut ve1);
20+
for i in 0..ve1.len() - 1 {
21+
assert!(ve1[i] <= ve1[i + 1]);
22+
}
23+
}
24+
25+
#[test]
26+
fn ascending() {
27+
//pre-sorted
28+
let mut ve2 = vec![1, 2, 3, 4, 5, 6];
29+
bubble_sort(&mut ve2);
30+
for i in 0..ve2.len() - 1 {
31+
assert!(ve2[i] <= ve2[i + 1]);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)