Open qinheping opened 4 months ago
Hi @qinheping and @feliperodri , can I please give this a try, thank you.
Hi @carolynzech, @celinval, @qinheping, @feliperodri; I've been working on the challenge to verify the memory safety for this challenge. Below is the code I have written so far to prove that undefined behavior doesn't exists for clear
function in LinkedList
:
use kani;
#[cfg(kani)]
#[kani::proof]
fn unbounded_check_for_clear() {
let size: i8 = kani::any();
let mut size_copy: i8 = size.clone();
let mut list: LinkedList<i8> = LinkedList::new();
// create a arbitraty size linkedlist
loop {
if size_copy == 0 {
break;
}
list.push_back(size_copy);
match size_copy.is_positive() {
true => size_copy -= 1,
false => size_copy += 1,
}
}
// check if the original kani produced size aligns with the linked list
assert_eq!(list.contains(&size), true);
assert_eq!(list.len(), size.abs().try_into().unwrap());
// clear all the items
list.clear();
//check again
assert_eq!(list.contains(&size), false);
assert_eq!(list.len(), 0);
assert!(list.is_empty());
}
I have some confusions:
thank you for your time and help.
Link to PR: #30 Link to challenge: 0005-linked-list.md