some more tests

This commit is contained in:
Michael Zhang 2020-02-20 21:44:19 -06:00
parent 5546a13c50
commit 0334b5cf33
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter, Write};
use std::fmt::{self, Debug, Formatter};
use std::marker::PhantomData;
use std::mem;
use std::ptr::NonNull;
use symbol::Symbol;
@ -110,6 +110,15 @@ impl<T> List<T> {
IntoIter(self.head)
}
/// Returns the head of the list
pub fn head(&self) -> Option<&T> {
if let Some(ref node) = self.head {
unsafe { node.as_ref() }.data.as_ref()
} else {
None
}
}
/// Returns the tail of the list
pub fn tail(&self) -> Option<&T> {
if let Some(ref node) = self.tail {
@ -186,11 +195,23 @@ mod tests {
prop_assert!(list.iter().eq(vec.iter()));
}
#[test]
fn return_ends(vec in vec(any::<u32>(), SizeRange::default())) {
prop_assume!(vec.len() > 0, "can't return any elements of a 0-sized vec");
let mut list = List::new();
for item in vec.iter() {
list.insert(*item);
}
prop_assert_eq!(list.head(), vec.first(), "heads");
prop_assert_eq!(list.tail(), vec.last(), "tails");
}
#[test]
fn test_remove_by_key(mut vec in vec(any::<u32>(), SizeRange::default()), index in any::<Index>()) {
prop_assume!(vec.len() == 0, "can't remove from a 0-sized vec");
prop_assume!(vec.len() > 0, "can't remove from a 0-sized vec");
let index = index.index(vec.len());
prop_assume!(index >= vec.len(), "ind is bigger than vec");
prop_assume!(index < vec.len(), "ind is bigger than vec");
let mut list = List::new();
let mut saved_key = None;