()
| 170 | |
| 171 | #[test] |
| 172 | fn evicts_when_full() { |
| 173 | let mut cache = CacheMap::<NumCache>::new(3); |
| 174 | let mut evicted = None; |
| 175 | cache |
| 176 | .insert(0, NumCache(()), |index, _| { |
| 177 | evicted = Some(index); |
| 178 | Ok(()) |
| 179 | }) |
| 180 | .unwrap(); |
| 181 | assert_eq!(evicted, None); |
| 182 | cache |
| 183 | .insert(1, NumCache(()), |index, _| { |
| 184 | evicted = Some(index); |
| 185 | Ok(()) |
| 186 | }) |
| 187 | .unwrap(); |
| 188 | assert_eq!(evicted, None); |
| 189 | cache |
| 190 | .insert(2, NumCache(()), |index, _| { |
| 191 | evicted = Some(index); |
| 192 | Ok(()) |
| 193 | }) |
| 194 | .unwrap(); |
| 195 | assert_eq!(evicted, None); |
| 196 | cache |
| 197 | .insert(3, NumCache(()), |index, _| { |
| 198 | evicted = Some(index); |
| 199 | Ok(()) |
| 200 | }) |
| 201 | .unwrap(); |
| 202 | assert!(evicted.is_some()); |
| 203 | |
| 204 | // Check that three of the four items inserted are still there and that the most recently |
| 205 | // inserted is one of them. |
| 206 | let num_items = (0..=3).filter(|k| cache.contains_key(*k)).count(); |
| 207 | assert_eq!(num_items, 3); |
| 208 | assert!(cache.contains_key(3)); |
| 209 | } |
| 210 | } |
nothing calls this directly
no test coverage detected