Skip to content

Commit ef8846f

Browse files
author
quintanamo
committed
clean up tests
1 parent a815580 commit ef8846f

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/sorting.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,21 @@ mod tests {
3030
use super::insertion_sort;
3131
use super::is_sorted;
3232

33+
const INPUTS: [[i32; 5]; 5] = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 1, 1, 2, 3], [5, 1, 4, 2, 3], [5, 1, 2, 5, 5]];
34+
3335
#[test]
3436
fn test_is_sorted() {
35-
let mut input: Vec<i32> = [5,2,3,1,4].to_vec();
36-
assert_eq!(is_sorted(input), false);
37-
input = [1, 2, 3, 4, 5].to_vec();
38-
assert_eq!(is_sorted(input), true);
39-
input = [1, 1, 2, 2, 3].to_vec();
40-
assert_eq!(is_sorted(input), true);
37+
const EXPECTED_RESULTS: [bool; 5] = [true, false, true, false, false];
38+
for i in 0..INPUTS.len() {
39+
assert_eq!(is_sorted(INPUTS[i].to_vec()), EXPECTED_RESULTS[i]);
40+
}
4141
}
4242

4343
#[test]
4444
fn test_insertion_sort() {
45-
let mut input: Vec<i32> = [5,2,3,1,4].to_vec();
46-
let mut output: Vec<i32> = insertion_sort(input);
47-
assert_eq!(is_sorted(output), true);
48-
input = [1, 1, 2, 1, 1].to_vec();
49-
output = insertion_sort(input);
50-
assert_eq!(is_sorted(output), true);
45+
for i in 0..INPUTS.len() {
46+
let sorted: Vec<i32> = insertion_sort(INPUTS[i].to_vec());
47+
assert_eq!(is_sorted(sorted), true);
48+
}
5149
}
5250
}

0 commit comments

Comments
 (0)