Skip to content

Commit

Permalink
Merge pull request #28 from musicinmybrain/quickcheck-v1
Browse files Browse the repository at this point in the history
Fix some bounds-arithmetic flaws in the tests, and update to quickcheck v1
  • Loading branch information
droundy authored Sep 14, 2024
2 parents 35d71c6 + fd823d5 commit 36e1b4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ repository = "https://github.com/droundy/arrayref"
documentation = "https://docs.rs/arrayref"

[dev-dependencies]
quickcheck = "0.6"
quickcheck = "1.0"
16 changes: 12 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ mod test {
#[test]
fn check_array_ref_5() {
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() < offset + 5 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() < offset + 5
if data.len() < 5 || data.len() - 5 < offset {
return quickcheck::TestResult::discard();
}
let out = array_ref!(data, offset, 5);
Expand All @@ -351,7 +353,9 @@ mod test {
#[test]
fn check_array_ref_out_of_bounds_5() {
fn f(data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() >= offset + 5 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() >= offset + 5
if data.len() >= 5 && data.len() - 5 >= offset {
return quickcheck::TestResult::discard();
}
quickcheck::TestResult::must_fail(move || {
Expand All @@ -364,7 +368,9 @@ mod test {
#[test]
fn check_array_mut_ref_7() {
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() < offset + 7 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() < offset + 7
if data.len() < 7 || data.len() - 7 < offset {
return quickcheck::TestResult::discard();
}
let out = array_mut_ref!(data, offset, 7);
Expand All @@ -377,7 +383,9 @@ mod test {
#[test]
fn check_array_mut_ref_out_of_bounds_32() {
fn f(mut data: Vec<u8>, offset: usize) -> quickcheck::TestResult {
if data.len() >= offset + 32 {
// Compute the following, with correct results even if the sum would overflow:
// if data.len() >= offset + 32
if data.len() >= 32 && data.len() - 32 >= offset {
return quickcheck::TestResult::discard();
}
quickcheck::TestResult::must_fail(move || {
Expand Down

0 comments on commit 36e1b4c

Please sign in to comment.