@@ -30,23 +30,21 @@ mod tests {
30
30
use super :: insertion_sort;
31
31
use super :: is_sorted;
32
32
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
+
33
35
#[ test]
34
36
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
+ }
41
41
}
42
42
43
43
#[ test]
44
44
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
+ }
51
49
}
52
50
}
0 commit comments