Skip to content

Commit

Permalink
test: add fuzz tests for left/right_encode
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Nov 19, 2023
1 parent a73c23d commit 96cc848
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,41 @@ mod tests {
}

#[test]
fn test_left_encode() {
fn left_encode_injective() {
bolero::check!().with_type::<(u64, u64)>().cloned().for_each(|(a, b)| {
let mut buf_a = [0u8; 9];
let mut buf_b = [0u8; 9];

let a_e = left_encode(&mut buf_a, a);
let b_e = left_encode(&mut buf_b, b);

if a == b {
assert_eq!(a_e, b_e);
} else {
assert_ne!(a_e, b_e);
}
});
}

#[test]
fn right_encode_injective() {
bolero::check!().with_type::<(u64, u64)>().cloned().for_each(|(a, b)| {
let mut buf_a = [0u8; 9];
let mut buf_b = [0u8; 9];

let a_e = right_encode(&mut buf_a, a);
let b_e = right_encode(&mut buf_b, b);

if a == b {
assert_eq!(a_e, b_e);
} else {
assert_ne!(a_e, b_e);
}
});
}

#[test]
fn left_encode_test_vectors() {
let mut buf = [0; 9];

assert_eq!(left_encode(&mut buf, 0), [1, 0]);
Expand All @@ -475,7 +509,7 @@ mod tests {
}

#[test]
fn test_right_encode() {
fn right_encode_test_vectors() {
let mut buf = [0; 9];

assert_eq!(right_encode(&mut buf, 0), [0, 1]);
Expand Down

0 comments on commit 96cc848

Please sign in to comment.