Skip to content

Commit

Permalink
Use u8 test indices so quickcheck is less likely to go out of bounds.
Browse files Browse the repository at this point in the history
(cherry picked from commit d110067)
  • Loading branch information
cuviper committed Jun 16, 2022
1 parent be700ef commit 8d02160
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ quickcheck_limit! {
})
}

fn swap_indices(vec: Vec<u8>, a: usize, b: usize) -> TestResult {
// Use `u8` test indices so quickcheck is less likely to go out of bounds.
fn swap_indices(vec: Vec<u8>, a: u8, b: u8) -> TestResult {
let mut set = IndexSet::<u8>::from_iter(vec);
let a = usize::from(a);
let b = usize::from(b);

if a >= set.len() || b >= set.len() {
return TestResult::discard();
}
Expand All @@ -236,8 +240,12 @@ quickcheck_limit! {
TestResult::passed()
}

fn move_index(vec: Vec<u8>, from: usize, to: usize) -> TestResult {
// Use `u8` test indices so quickcheck is less likely to go out of bounds.
fn move_index(vec: Vec<u8>, from: u8, to: u8) -> TestResult {
let mut set = IndexSet::<u8>::from_iter(vec);
let from = usize::from(from);
let to = usize::from(to);

if from >= set.len() || to >= set.len() {
return TestResult::discard();
}
Expand Down

0 comments on commit 8d02160

Please sign in to comment.