Skip to content

Commit 553d2c1

Browse files
committed
doubly-linked-list: Test len in more places
I simply thought we could increase the thoroughness without being an undue burden on readability or student completion. This is limited to testing len in additional places in tests that were already testing len or is_empty. It hasn't added len in tests that didn't already have either of those two.
1 parent 32e76e9 commit 553d2c1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

exercises/doubly-linked-list/tests/doubly-linked-list.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn basics_single_element_back() {
3030

3131
assert_eq!(list.pop_back(), Some(5));
3232

33+
assert_eq!(list.len(), 0);
3334
assert!(list.is_empty());
3435
}
3536

@@ -39,10 +40,11 @@ fn basics_push_pop_at_back() {
3940
let mut list: LinkedList<i32> = LinkedList::new();
4041
for i in 0..10 {
4142
list.push_back(i);
43+
assert_eq!(list.len(), i as usize + 1);
4244
assert!(!list.is_empty());
4345
}
44-
assert_eq!(list.len(), 10);
4546
for i in (0..10).rev() {
47+
assert_eq!(list.len(), i as usize + 1);
4648
assert!(!list.is_empty());
4749
assert_eq!(i, list.pop_back().unwrap());
4850
}
@@ -62,6 +64,7 @@ fn basics_single_element_front() {
6264

6365
assert_eq!(list.pop_front(), Some(5));
6466

67+
assert_eq!(list.len(), 0);
6568
assert!(list.is_empty());
6669
}
6770

@@ -71,10 +74,11 @@ fn basics_push_pop_at_front() {
7174
let mut list: LinkedList<i32> = LinkedList::new();
7275
for i in 0..10 {
7376
list.push_front(i);
77+
assert_eq!(list.len(), i as usize + 1);
7478
assert!(!list.is_empty());
7579
}
76-
assert_eq!(list.len(), 10);
7780
for i in (0..10).rev() {
81+
assert_eq!(list.len(), i as usize + 1);
7882
assert!(!list.is_empty());
7983
assert_eq!(i, list.pop_front().unwrap());
8084
}
@@ -89,12 +93,15 @@ fn basics_push_front_pop_back() {
8993
let mut list: LinkedList<i32> = LinkedList::new();
9094
for i in 0..10 {
9195
list.push_front(i);
96+
assert_eq!(list.len(), i as usize + 1);
9297
assert!(!list.is_empty());
9398
}
9499
for i in 0..10 {
100+
assert_eq!(list.len(), 10 - i as usize);
95101
assert!(!list.is_empty());
96102
assert_eq!(i, list.pop_back().unwrap());
97103
}
104+
assert_eq!(list.len(), 0);
98105
assert!(list.is_empty());
99106
}
100107

@@ -104,12 +111,15 @@ fn basics_push_back_pop_front() {
104111
let mut list: LinkedList<i32> = LinkedList::new();
105112
for i in 0..10 {
106113
list.push_back(i);
114+
assert_eq!(list.len(), i as usize + 1);
107115
assert!(!list.is_empty());
108116
}
109117
for i in 0..10 {
118+
assert_eq!(list.len(), 10 - i as usize);
110119
assert!(!list.is_empty());
111120
assert_eq!(i, list.pop_front().unwrap());
112121
}
122+
assert_eq!(list.len(), 0);
113123
assert!(list.is_empty());
114124
}
115125

0 commit comments

Comments
 (0)