From 4f7b2c8ec59587ba11908bec975dd0719f389797 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Tue, 10 Aug 2021 17:16:33 +0100 Subject: [PATCH] Confirm that densemap len wont panic if lots of retired items --- backend/common/src/dense_map.rs | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/backend/common/src/dense_map.rs b/backend/common/src/dense_map.rs index f3ee90f..3dfd420 100644 --- a/backend/common/src/dense_map.rs +++ b/backend/common/src/dense_map.rs @@ -131,3 +131,37 @@ where } } } + +#[cfg(test)] +mod test { + + use super::*; + + #[test] + fn len_doesnt_panic_if_lots_of_retired() { + + let mut map = DenseMap::::new(); + + let id1 = map.add(1); + let id2 = map.add(2); + let id3 = map.add(3); + + assert_eq!(map.len(), 3); + + map.remove(id1); + map.remove(id2); + + assert_eq!(map.len(), 1); + + map.remove(id3); + + assert_eq!(map.len(), 0); + + map.remove(id1); + map.remove(id1); + map.remove(id1); + + assert_eq!(map.len(), 0); + } + +} \ No newline at end of file