@@ -2,17 +2,38 @@ import core::*;
2
2
3
3
use std;
4
4
import std:: list;
5
- import std:: list:: head;
6
- import std:: list:: tail;
7
- import std:: list:: from_vec;
5
+ import std:: list:: { from_vec, head, is_empty, is_not_empty, tail} ;
8
6
import option;
9
7
8
+ #[ test]
9
+ fn test_is_empty ( ) {
10
+ let empty : list:: list < int > = from_vec ( [ ] ) ;
11
+ let full1 = from_vec ( [ 1 ] ) ;
12
+ let full2 = from_vec ( [ 'r' , 'u' ] ) ;
13
+
14
+ assert is_empty( empty) ;
15
+ assert ! is_empty( full1) ;
16
+ assert ! is_empty( full2) ;
17
+
18
+ assert ! is_not_empty( empty) ;
19
+ assert is_not_empty ( full1) ;
20
+ assert is_not_empty ( full2) ;
21
+ }
22
+
10
23
#[ test]
11
24
fn test_from_vec ( ) {
12
25
let l = from_vec ( [ 0 , 1 , 2 ] ) ;
26
+
27
+ check is_not_empty ( l) ;
13
28
assert ( head ( l) == 0 ) ;
14
- assert ( head ( tail ( l) ) == 1 ) ;
15
- assert ( head ( tail ( tail ( l) ) ) == 2 ) ;
29
+
30
+ let tail_l = tail ( l) ;
31
+ check is_not_empty ( tail_l) ;
32
+ assert ( head ( tail_l) == 1 ) ;
33
+
34
+ let tail_tail_l = tail ( tail_l) ;
35
+ check is_not_empty ( tail_tail_l) ;
36
+ assert ( head ( tail_tail_l) == 2 ) ;
16
37
}
17
38
18
39
#[ test]
@@ -24,9 +45,17 @@ fn test_from_vec_empty() {
24
45
#[ test]
25
46
fn test_from_vec_mut ( ) {
26
47
let l = from_vec ( [ mutable 0 , 1 , 2 ] ) ;
48
+
49
+ check is_not_empty ( l) ;
27
50
assert ( head ( l) == 0 ) ;
28
- assert ( head ( tail ( l) ) == 1 ) ;
29
- assert ( head ( tail ( tail ( l) ) ) == 2 ) ;
51
+
52
+ let tail_l = tail ( l) ;
53
+ check is_not_empty ( tail_l) ;
54
+ assert ( head ( tail_l) == 1 ) ;
55
+
56
+ let tail_tail_l = tail ( tail_l) ;
57
+ check is_not_empty ( tail_tail_l) ;
58
+ assert ( head ( tail_tail_l) == 2 ) ;
30
59
}
31
60
32
61
#[ test]
0 commit comments