Extend methods run through arbitrary-model-tests

This commit is contained in:
Wim Looman
2020-01-13 19:44:04 +01:00
parent 2f5823df14
commit 8780cb5fe1
2 changed files with 27 additions and 2 deletions
+13 -1
View File
@@ -26,11 +26,16 @@ arbitrary_stateful_operations! {
fn insert(&mut self, index: usize, item: T);
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn pop(&mut self) -> Option<T>;
fn push(&mut self, item: T);
fn remove(&mut self, index: usize) -> T;
fn resize(&mut self, new_len: usize, new_val: T);
fn swap_remove(&mut self, index: usize) -> T;
fn truncate(&mut self, new_len: usize);
}
equal_with(Vec::from_iter) {
fn split_off(&mut self, at: usize) -> impl IntoIterator<Item = T>;
fn drain(&self, range: R) -> impl Iterator<Item = T>;
fn iter(&self) -> impl Iterator<Item = &T>;
fn iter_mut(&self) -> impl Iterator<Item = &mut T>;
@@ -39,13 +44,20 @@ arbitrary_stateful_operations! {
pre {
match self {
Self::insert { index, .. } if index > model.len() => {
Self::insert { index, .. } | Self::split_off { at: index } if index > model.len() => {
// TODO: Should test that these identically panic
return;
}
Self::remove { index } | Self::swap_remove { index } if index >= model.len() => {
// TODO: Should test that these identically panic
return;
}
Self::insert { .. } | Self::push { .. } if model.len() == CAPACITY => {
return;
}
Self::resize { new_len, .. } if new_len > CAPACITY => {
return;
}
Self::drain { ref range } => {
// TODO: Should test that these identically panic
let start = match range.start_bound() {
+14 -1
View File
@@ -26,11 +26,16 @@ arbitrary_stateful_operations! {
fn insert(&mut self, index: usize, item: T);
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn pop(&mut self) -> Option<T>;
fn push(&mut self, item: T);
fn remove(&mut self, index: usize) -> T;
fn resize(&mut self, new_len: usize, new_val: T);
fn swap_remove(&mut self, index: usize) -> T;
fn truncate(&mut self, new_len: usize);
}
equal_with(Vec::from_iter) {
fn split_off(&mut self, at: usize) -> impl IntoIterator<Item = T>;
fn drain(&self, range: R) -> impl Iterator<Item = T>;
fn iter(&self) -> impl Iterator<Item = &T>;
fn iter_mut(&self) -> impl Iterator<Item = &mut T>;
@@ -39,10 +44,18 @@ arbitrary_stateful_operations! {
pre {
match self {
Self::insert { index, .. } if index > model.len() => {
Self::insert { index, .. } | Self::split_off { at: index } if index > model.len() => {
// TODO: Should test that these identically panic
return;
}
Self::remove { index } | Self::swap_remove { index } if index >= model.len() => {
// TODO: Should test that these identically panic
return;
}
// Arbitrary limit to avoid allocating too large a buffer
Self::resize { new_len, .. } if new_len > 4 * CAPACITY => {
return;
}
Self::drain { ref range } => {
// TODO: Should test that these identically panic
let start = match range.start_bound() {