Skip to content

Commit

Permalink
Added memory leak tests for overwrite and read
Browse files Browse the repository at this point in the history
  • Loading branch information
felix91gr committed Mar 17, 2023
1 parent e84875f commit ff1c9fa
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions exercises/practice/circular-buffer/tests/circular-buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ fn clear_actually_frees_up_its_elements() {
assert_eq!(Rc::strong_count(&element), 1);
}

#[test]
#[ignore]
fn overwrite_frees_up_the_cleared_elements() {
let mut buffer = CircularBuffer::new(1);
let element_to_replace = Rc::new(());
let new_element = Rc::new(());
assert!(buffer.write(Rc::clone(&element_to_replace)).is_ok());
assert_eq!(Rc::strong_count(&element_to_replace), 2);
buffer.overwrite(Rc::clone(&new_element));
assert_eq!(Rc::strong_count(&element_to_replace), 1);
}

#[test]
#[ignore]
fn read_frees_up_the_read_element() {
let mut buffer = CircularBuffer::new(1);
let element = Rc::new(());
assert!(buffer.write(Rc::clone(&element)).is_ok());
assert_eq!(Rc::strong_count(&element), 2);
assert!(buffer.read().is_ok());
assert_eq!(Rc::strong_count(&element), 1);
}

#[test]
#[ignore]
fn overwrite_acts_like_write_on_non_full_buffer() {
Expand Down

0 comments on commit ff1c9fa

Please sign in to comment.