diff options
author | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-04-06 11:04:39 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-04-06 11:04:39 +0300 |
commit | 41ae373d927364edc401377250a6f3fb87f9300d (patch) | |
tree | 121b0e71348244430700facf0aab33822fc83c48 | |
parent | a8ab93ee575820ebf331d773c331aec75c0c9822 (diff) | |
download | lookup-41ae373d927364edc401377250a6f3fb87f9300d.tar.gz |
fix: only insert once
Sponsored-by: author
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index ebb5c4f..7fd05af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,9 @@ impl Container { } fn insert(&mut self, n: i32) { - self.numbers.push(n); + if !self.contains(n) { + self.numbers.push(n); + } } fn remove(&mut self, n: i32) -> Option<i32> { @@ -76,4 +78,17 @@ mod test { c.remove(0); assert!(c.is_empty()); } + + #[test] + fn inserts_only_once() { + let mut c = Container::default(); + assert!(!c.contains(0)); + c.insert(0); + c.insert(0); + assert_eq!(c.len(), 1); + assert!(!c.is_empty()); + assert!(c.contains(0)); + c.remove(0); + assert!(c.is_empty()); + } } |