Skip to content

Commit

Permalink
Add from impl tests
Browse files Browse the repository at this point in the history
Add tests for the witness from implementations to kill all the mutants
found by cargo mutants.
  • Loading branch information
jamillambert committed Feb 11, 2025
1 parent 2f95064 commit 7e66091
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions primitives/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,33 @@ mod test {
assert_eq!(witness.size(), 6);
}

#[test]
fn witness_from_impl() {
// Test From implementations with the same 2 elements
let vec = vec![vec![11], vec![21, 22]];
let slice_vec: &[Vec<u8>] = &vec;
let slice_slice: &[&[u8]] = &[&[11u8], &[21, 22]];
let vec_slice: Vec<&[u8]> = vec![&[11u8], &[21, 22]];

let witness_vec_vec = Witness::from(vec.clone());
let witness_slice_vec = Witness::from(slice_vec);
let witness_slice_slice = Witness::from(slice_slice);
let witness_vec_slice = Witness::from(vec_slice);

let mut expected = Witness::from_slice(&vec);
assert_eq!(expected.len(), 2);
assert_eq!(expected.to_vec(), vec);

assert_eq!(witness_vec_vec, expected);
assert_eq!(witness_slice_vec, expected);
assert_eq!(witness_slice_slice, expected);
assert_eq!(witness_vec_slice, expected);

// Test clear method
expected.clear();
assert!(expected.is_empty());
}

#[test]
#[cfg(feature = "serde")]
fn serde_bincode_backward_compatibility() {
Expand Down

0 comments on commit 7e66091

Please sign in to comment.