@@ -2,17 +2,38 @@ import core::*;
22
33use std;
44import 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} ;
86import option;
97
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+
1023#[ test]
1124fn test_from_vec ( ) {
1225 let l = from_vec ( [ 0 , 1 , 2 ] ) ;
26+
27+ check is_not_empty ( l) ;
1328 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 ) ;
1637}
1738
1839#[ test]
@@ -24,9 +45,17 @@ fn test_from_vec_empty() {
2445#[ test]
2546fn test_from_vec_mut ( ) {
2647 let l = from_vec ( [ mutable 0 , 1 , 2 ] ) ;
48+
49+ check is_not_empty ( l) ;
2750 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 ) ;
3059}
3160
3261#[ test]
0 commit comments